Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

applescript or automator to export safari bookmarks

Can I use applescript or automator to export safari bookmarks? I would like to periodically save an html copy of my bookmarks. Is it possible?
Thanks.

MacBook Pro i7 2.66GHz, Mac OS X (10.6.5)

Posted on Dec 18, 2010 6:35 PM

Reply
Question marked as Best reply

Posted on Dec 18, 2010 7:39 PM

c_kyr wrote:
Can I use applescript or automator to export safari bookmarks? I would like to periodically save an html copy of my bookmarks. Is it possible?


As far as I know, not to html. Bookmarks are in a binary .plist format. You can convert to a readable xml format with the following Applescript:

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;">
do shell script "/usr/bin/plutil -convert xml1 $HOME/Library/Safari/Bookmarks.plist -o $HOME/Desktop/Bookmarks.xml"</pre>
3 replies
Question marked as Best reply

Dec 18, 2010 7:39 PM in response to c_kyr

c_kyr wrote:
Can I use applescript or automator to export safari bookmarks? I would like to periodically save an html copy of my bookmarks. Is it possible?


As far as I know, not to html. Bookmarks are in a binary .plist format. You can convert to a readable xml format with the following Applescript:

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;">
do shell script "/usr/bin/plutil -convert xml1 $HOME/Library/Safari/Bookmarks.plist -o $HOME/Desktop/Bookmarks.xml"</pre>

Dec 19, 2010 3:42 AM in response to c_kyr

The following short script should save an html copy of your Safari bookmarks on the desktop. What do you exactly mean by “periodically” though?

*tell application "Safari" to activate*
*tell application "System Events" to tell process "Safari"*
* click menu item "Export Bookmarks…" of menu 1 of menu bar item "File" of menu bar 1*
* keystroke "d" using command down* -- to save on the desktop
* click button "Save" of window 1*
* if sheet 1 of window 1 exists then click button "Replace" of sheet 1 of window 1*
*end tell*


Don't forget to activate [GUI Scripting|http://www.macosxautomation.com/applescript/uiscripting/index.html].

Message was edited by: Pierre L.

Dec 19, 2010 4:02 AM in response to c_kyr

You can also use System Events to read the .plist file and build the HTML. Something like:

set myHTML to cjmSafariBookmarkHTML()
on cjmSafariBookmarkHTML()
set urlListText to "<html><body>" & return & "<h1>Safari Bookmarks - " & (short date string of (current date)) & "</h1>" & return
set theDBPath to (POSIX path of (((path to current user folder) as string) & "Library:Safari:Bookmarks.plist"))
tell application "System Events"
try
set myBundle to value of property list items of property list file theDBPath
repeat with mySet in (item 2 of myBundle)
try
if (|Children| of mySet) is not equal to {} then
set urlListText to urlListText & "<h2>" & (|Title| of mySet) & "</h2>" & return
set urlListText to urlListText & "<ul>" & return
repeat with myDict in (|Children| of mySet)
set urlListText to urlListText & "<li><a href=\"" & (URLString of myDict) & "\">" & (|title| of URIDictionary of myDict) & "</a></li>" & return
end repeat
set urlListText to urlListText & "<ul>" & return
end if
end try
end repeat
on error theErr
activate
display dialog theErr
end try
end tell
set urlListText to urlListText & "</body></html>"
return urlListText
end cjmSafariBookmarkHTML



You can then save the resulting text as a file.

Best wishes

John M

Message was edited by: John Maisey - fixed formatting.

applescript or automator to export safari bookmarks

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.