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:
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?
Best Answer
After some googling and learning XPath expressions, the solution is really simple:
The following shell script - let say its name is
dump_bookmarks.sh
,and using it as
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