Have many bookmarks in the Safari's Favorites. Let say, have an folder called perl and it contains many links and also subforlders with links, like in the screenshot:

enter image description here

Need to extract all bookmarked links from the perl folder and it's subfolders using ONLY Terminal's command line. E.g. want run some command in the Terminal, like:

get_my_bookmarks perl

and the result will be a list of URLs.

It is possible to achieve this with applescrit, e.g. with

 osascript -e '... some applescript voodoo ...'

or by using some tool and extracting the wanted links info from the binary ~/Library/Safari/Bookmarks.plist, e.g. the following

/usr/libexec/PlistBuddy -x -c Print ~/Library/Safari/Bookmarks.plist

dumps the whole plist (xml) - but how to easily extract only URLs from one defined bookmark-folder? Any idea for some simple way?

1 Answer 1


After some googling and learning XPath expressions, the solution is really simple:

The following shell script - let say its name is dump_bookmarks.sh,

for foldername
    /usr/libexec/PlistBuddy -x -c Print ~/Library/Safari/Bookmarks.plist | \
    xmlstarlet sel --net -t -v "//key[.='Title']/following-sibling::string[.='$foldername']/parent::node()//key[.='URLString']/following-sibling::string[1]"
    echo    #print an newline after the last entry

and using it as

./print_bookmarks.sh perl  #argument is the bookmark-folder name

will print a list of bookmarked URLs, like for the above screenshot will print:


For the script you need install the xmlstarlet command, for example using Macports

sudo port install xmlstarlet

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .