PDA

View Full Version : Create bookmarks on startup?




Sinergi
Jun 13, 2012, 04:01 AM
Hey,

I was wondering if it's possible to create a set of bookmarks for Safari on startup or adding a set of bookmarks to a current plist file without deleting current bookmarks?

I have found that the bookmarks file is in ~/Library/Safari/Bookmarks.plist but unfortunately not sure how to create a new bookmark from ARD.

Any advice would be greatly appreciated!



kryten2
Jun 13, 2012, 01:05 PM
Did a quick Google and found this script. Props and credit to whoever made it. I adapted it a little bit.

Quote from the maker :

I should also warn anyone interested to practice on a copy of your bookmarks plist, and keep a backup copy when you're working on the main plist, because if you mess up the xml references System Events has an unfortunate tendency to zero out the file. Don't want all your bookmarks to go up in smoke without a backup.


The script makes 2 new bookmarks in the Bookmarks Menu at the end of any existing bookmarks. Change to your needs.


tell application "System Events"
set theURIstrings to {"http://somewhere.someplace.somehow.org", "http://somewhere.someplace.somehow.org"}
repeat with anURIString in theURIstrings
set theUUID to do shell script "uuidgen"
tell application "Finder" to set titleString to text returned of (display dialog "This is the title that will appear in the Bookmarks menu." with title "Bookmark Title Dialog" default answer "Title for my Bookmark" buttons {"Cancel", "OK"} default button 1)
-- Change the following line to the location of your copy of the Bookmark.plist file
set thePlistFile to property list file "/Users/test/Desktop/Bookmarks.plist"
tell property list item "Children" of contents of thePlistFile
set theMenuXML to item 1 of (every property list item whose ((property list item "Title")'s value is "BookmarksMenu"))
tell theMenuXML's property list item "Children"
set newDict to make new property list item at end of property list items with properties {kind:record}
tell newDict
set URIDict to make new property list item at end of property list items with properties {kind:record, name:"URIDictionary"}
tell URIDict
make new property list item at end of property list items with properties {kind:string, name:"title", value:titleString}
end tell
make new property list item at end of property list items with properties {kind:string, name:"URLString", value:anURIString}
make new property list item at end of property list items with properties {kind:string, name:"WebBookmarkType", value:"WebBookmarkTypeLeaf"}
make new property list item at end of property list items with properties {kind:string, name:"WebBookmarkUUID", value:theUUID}
end tell
end tell
end tell
end repeat
end tell


Or this variant. Please note if you put 5 items in the theURIstrings you need 5 items in titleStrings! In short make sure you have the same number of items in both lists!

tell application "System Events"
set theURIstrings to {"http://www.apple.com/nl/", "http://www.macrumors.com/"}
set titleStrings to {"Apple", "Mac Rumors: Apple Mac Rumors and News You Care About"}
repeat with i from 1 to number of items in theURIstrings
set anURIString to item i of theURIstrings
set theUUID to do shell script "uuidgen"
-- Change the following line to the location of your copy of the Bookmark.plist file
set thePlistFile to property list file "/Users/test/Desktop/Bookmarks.plist"
tell property list item "Children" of contents of thePlistFile
set theMenuXML to item 1 of (every property list item whose ((property list item "Title")'s value is "BookmarksMenu"))
tell theMenuXML's property list item "Children"
set newDict to make new property list item at end of property list items with properties {kind:record}
tell newDict
set URIDict to make new property list item at end of property list items with properties {kind:record, name:"URIDictionary"}
tell URIDict
make new property list item at end of property list items with properties {kind:string, name:"title", value:item i of titleStrings}
end tell
make new property list item at end of property list items with properties {kind:string, name:"URLString", value:anURIString}
make new property list item at end of property list items with properties {kind:string, name:"WebBookmarkType", value:"WebBookmarkTypeLeaf"}
make new property list item at end of property list items with properties {kind:string, name:"WebBookmarkUUID", value:theUUID}
end tell
end tell
end tell
end repeat
end tell


Info : http://macosxautomation.com/applescript/features/propertylists.html

Sinergi
Jul 3, 2012, 09:50 AM
Thanks kryten2.

I got the error System Events got an error: Cant get property list file "/Users/test/Dekstop/Bookmarks/plist".

I tried changing that path to ~/Library/Safari/Bookmarks.plist but this through a different error.

Any advice?

kryten2
Jul 3, 2012, 10:49 AM
I got the error System Events got an error: Cant get property list file "/Users/test/Dekstop/Bookmarks/plist".

Normal error because you didn't see/read this line in the script :

--Change the following line to the location of your copy of the Bookmark.plist file

Test is my username, yours is probably something different. So make a copy of your Bookmarks.plist file, put it on your Desktop and change the line accordingly. If your username is bob change to "/Users/bob/Desktop/Bookmarks.plist"

I tried changing that path to ~/Library/Safari/Bookmarks.plist but this through a different error.

You also didn't see/read the first quote from my answer about using a copy of your Bookmarks.plist. But if you want to I'm not going to stop you. Try changing to :

"/Users/yourusernamehere/Library/Safari/Bookmarks.plist"

Sinergi
Jul 4, 2012, 03:11 AM
Hi kryten2, cheers for the help fella although I did read your information and changed accordingly. We use network accounts so no user directories exist in /Users/ so '~/Library/Safari/Bookmarks.plist' won't work for me, any idea?

Also, I did make a copy of the bookmarks however I wasn't using the copy file. I did not think this made a difference, it seemed all the same.

Thanks

grim42
Jul 4, 2012, 06:10 AM
Try entering 'echo $HOME' in a terminal window to find out what the path to your home directory is and substitute it where you have '~'.

kryten2
Jul 4, 2012, 10:20 AM
You can try grim42's answer to see if the substitution works. After reading you're using network accounts it might be useful to try a different approach :

Using the Preference Editor to Manage Safari on this link : http://manuals.info.apple.com/en_US/UserMgmt_v10.6.pdf or http://www.computerworld.com/s/article/9028799/Hands_On_Inside_Apple_s_Managed_Preferences_Architecture?taxonomyId=123&intsrc=kc_feat&taxonomyName=macintosh_os

A managed login item script. Info : http://macosx.com/forums/mac-os-x-server/222002-forced-user-prefs-problems.html

General info : http://www.google.be/search?client=safari&rls=en&q=osx+server+Using+the+Preference+Editor+to+Manage+Safari+bookmarks&ie=UTF-8&oe=UTF-8&redir_esc=&ei=Rkj0T8-OKOrb0QXI4NiuBw#hl=nl&client=safari&rls=en&sclient=psy-ab&q=safari+bookmarks+workgroup+manager&oq=Safari+bookmarks+wor&gs_l=serp.1.0.0i30l2j0i5i30l2.538968.586408.0.595238.6.6.0.0.0.0.216.629.4j1j1.6.0...0.0.heLyEUye-EE&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=3d2dd9571fd6e1bf&biw=1281&bih=802

I know it's possible to provide clients with some bookmarks on other platforms so it must be achievable on OS X too.