title: Applescript: Edit bookmark.plist file with new URL
body: <pre><code>set some_host to "test.mydomain.com"
  
  try
      -- Ping the host.
      do shell script "ping -c 1 -t 1 " &amp; some_host
      -- Set ipAddr.
      set ipAddr to word 3 of result
      -- Combine the IP with the URL &amp; port.
      set urlAddr to "http://" &amp; ipAddr &amp; ":80"
      display dialog "Connection Successful. " &amp; urlAddr buttons {"OK"} default button 1
  on error
      -- if we get here, the ping failed
      display dialog "Conection failed. " &amp; some_host &amp; " is down" buttons {"OK"} default button 1
      return
  end try
  
  -- Update the URL with the new IP.
  tell application "System Events"
      tell property list file "~/Library/Safari/Bookmarks.plist"
      set value of property list item "key" to text of urlAddr
      end tell
  end tell
  </code></pre>
  
  <p><strong>Here's the error I get.</strong> I should mention that "key" would be replaced with the bookmarks name I'm trying to change. </p>
  
  <pre><code>error "System Events got an error: Can’t set property list item \"key\" of property list file \"~/Library/Safari/Bookmarks.plist\" to \"http://000.000.000.000:80\"." number -10006 from property list item "key" of property list file "~/Library/Safari/Bookmarks.plist"
  </code></pre>
  
  <p>Bookmark.plist example: So lets replace "Key" with "NVR Camera"</p>
  
  <pre><code>&lt;dict&gt;
          &lt;key&gt;URIDictionary&lt;/key&gt;
          &lt;dict&gt;
              &lt;key&gt;title&lt;/key&gt;
              &lt;string&gt;NVR Camera&lt;/string&gt;
          &lt;/dict&gt;
          &lt;key&gt;URLString&lt;/key&gt;
          &lt;string&gt;https://12.123.456.789:88&lt;/string&gt;
          &lt;key&gt;WebBookmarkType&lt;/key&gt;
          &lt;string&gt;WebBookmarkTypeLeaf&lt;/string&gt;
          &lt;key&gt;previewText&lt;/key&gt;
          &lt;string&gt;your description&lt;/string&gt;
          &lt;key&gt;previewTextIsUserDefined&lt;/key&gt;
          &lt;true/&gt;
      &lt;/dict&gt;
  </code></pre>
  
  <p>I'm trying to do this to update the URL automatically to the new IP if it changes. If anyone has a better solution I'm all ears! Thanks in advance!</p>