Skip to content

Instantly share code, notes, and snippets.

@hvalls
Last active November 23, 2022 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hvalls/e07ba7839da6403a7d4f997b30f3da8f to your computer and use it in GitHub Desktop.
Save hvalls/e07ba7839da6403a7d4f997b30f3da8f to your computer and use it in GitHub Desktop.
Add Safari bookmark
#!/bin/bash
cd /Users/{user}/Library/Safari
while IFS='#' read -r title url
do
/usr/libexec/PlistBuddy Bookmarks.plist -c "Add :Children:1:Children:0 dict"
/usr/libexec/PlistBuddy Bookmarks.plist -c "Add :Children:1:Children:0:URIDictionary dict"
/usr/libexec/PlistBuddy Bookmarks.plist -c "Add :Children:1:Children:0:URIDictionary:title string ${title}"
/usr/libexec/PlistBuddy Bookmarks.plist -c "Add :Children:1:Children:0:URLString string ${url}"
/usr/libexec/PlistBuddy Bookmarks.plist -c "Add :Children:1:Children:0:WebBookmarkType string WebBookmarkTypeLeaf"
done < "$1"
@djipih
Copy link

djipih commented Nov 23, 2022

Hello, Thank U for sharing this script ;)
Why are U using a loop ? Only the commands 'PlistBuddy' did the trick for me. For example :
/usr/libexec/PlistBuddy $HOME//Library/Safari/Bookmarks.plist -c "Add :Children:1:Children:0 dict"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment