Posted on 11-29-2012 02:10 PM
Not really a question, just wanted to share something that we've been looking to develop here in our labs for a long white now. Finally, after much R&D and banging of our heads along with some nifty help from Ryan on Mac Enterprise, here's a very simple script to ADD a Safari bookmark as the first item in your bookmark bar. Our script goes the extra mile and changes ANY +500 user account so all accounts (not root) are touched.
The biggest problem, understanding BOTH PlistBuddy and the Safari Bookmarks.plist.
enjoy
#!/bin/sh
# script to add a bookmark to the FRONT LEFT of the safari bookmark bar
# for all > 500 user accounts.
# to create your own links, just change the variables:
#
# LinkTitle = the name of the link you'd like to appear in your link bar
# LinkURL = the actual link to which you'll surf
# Bookmakrs = the Safari bookmarks file(s) to which you'll be adding the link
# LOG = whatever your sdout file is
# by David Koff, 2012 for the J. Paul Getty Trust
# many thanks to both Chris Norris (cnorris@getty.edy) & Ryan Manly (ryan.manly@gmail.com) for their invaluable input.
#----------------------------------------------------------
# Variables
#----------------------------------------------------------
# --- assignments ---
SCRIPTNAME=$0
LinkTitle="eAppraisal"
LinkURL="https://eappraisal.getty.edu/Halogen/welcome.jsp"
# --- executables ---
Plist="/usr/libexec/PlistBuddy"
# --- directories ---
LOG="/Library/Logs/Getty Installations.log"
# --- computationals ---
date=`date "+%A %m/%d/%Y %H:%M"`
over500=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
# ---------------------------------------------------------------------------
# Cycle through all users, backs up safari bookmarks & adds new link
# ---------------------------------------------------------------------------
for i in $over500
do
cd /Users/$i/Library/Safari
zip BookmarksBackup.zip Bookmarks.plist
echo "backup of bookmarks SUCCESSFUL for the $i account." >> $LOG
$Plist Bookmarks.plist -c "Add :Children:1:Children:0 dict" >> $LOG
$Plist Bookmarks.plist -c "Add :Children:1:Children:0:URIDictionary dict" >> $LOG
$Plist Bookmarks.plist -c "Add :Children:1:Children:0:URIDictionary:title string ${LinkTitle}" >> $LOG
$Plist Bookmarks.plist -c "Add :Children:1:Children:0:URLString string ${LinkURL}" >> $LOG
$Plist Bookmarks.plist -c "Add :Children:1:Children:0:WebBookmarkType string WebBookmarkTypeLeaf" >> $LOG
done
exit 0
Posted on 11-29-2012 02:33 PM
Thanks, this is going to be very useful
Posted on 03-19-2013 07:33 AM
Hi themacdweed, that is a great script. Do you know how to make a folder in Safari where bookmarks are place within that folder? Thank you for your help.
Posted on 10-10-2013 07:36 AM
I seem to be having some issues getting this script to work. I keep getting an error that the entry already exists for each of the Add lines. Has anyone had any success getting this to run, and if so, any advice?