Mac Create bookmarks on startup?

Sinergi

macrumors newbie
Original poster
May 8, 2011
17
0
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

macrumors 6502a
Mar 17, 2012
996
59
Belgium
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.


Code:
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!

Code:
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
 
Last edited:

Sinergi

macrumors newbie
Original poster
May 8, 2011
17
0
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?
 
Last edited:

kryten2

macrumors 6502a
Mar 17, 2012
996
59
Belgium
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 :

Code:
[COLOR="Red"]--Change the following line to the location of your copy of the Bookmark.plist file[/COLOR]
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

macrumors newbie
Original poster
May 8, 2011
17
0
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
 

Similar threads

Register on MacRumors! This sidebar will go away, and you'll see fewer ads.