Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 13, 2012, 05:01 AM   #1
Sinergi
macrumors newbie
 
Join Date: May 2011
Create bookmarks on startup?

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!
Sinergi is offline   0 Reply With Quote
Old Jun 13, 2012, 02:05 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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 :

Quote:
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/applescr...ertylists.html

Last edited by kryten2; Jun 13, 2012 at 06:35 PM.
kryten2 is offline   0 Reply With Quote
Old Jul 3, 2012, 10:50 AM   #3
Sinergi
Thread Starter
macrumors newbie
 
Join Date: May 2011
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 by Sinergi; Jul 3, 2012 at 11:11 AM.
Sinergi is offline   0 Reply With Quote
Old Jul 3, 2012, 11:49 AM   #4
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
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:
--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"

Quote:
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"
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Jul 4, 2012, 04:11 AM   #5
Sinergi
Thread Starter
macrumors newbie
 
Join Date: May 2011
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
Sinergi is offline   0 Reply With Quote
Old Jul 4, 2012, 07:10 AM   #6
grim42
macrumors newbie
 
Join Date: Jun 2008
Location: Cape Town, South Africa
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 '~'.
grim42 is offline   0 Reply With Quote
Old Jul 4, 2012, 11:20 AM   #7
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
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/artic...e=macintosh_os

A managed login item script. Info : http://macosx.com/forums/mac-os-x-se...-problems.html

General info : http://www.google.be/search?client=s...w=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.
__________________
Space Corps Directive 34124

Last edited by kryten2; Jul 4, 2012 at 01:33 PM.
kryten2 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Safari bookmarks tab annoying, why doesn't a click on the webpage close the bookmarks bobright OS X Mavericks (10.9) 1 Oct 25, 2013 05:19 PM
Firefox - Shortcut for activating bookmarks in Bookmarks Toolbar? rekhyt Mac Basics and Help 0 Oct 13, 2013 08:39 AM
Bookmarks bar, Bookmarks Menu, Bookmarks. shenfrey iOS 6 2 Jul 3, 2013 07:51 AM
Can't reorder bookmarks in Safari Bookmarks bar and iCloud syncing problem EthanMiller Mac Basics and Help 2 Dec 29, 2012 03:44 AM
iPhone bookmarks >iCloud > OS X move bookmarks to folder? poobear iCloud and Apple Services 0 Jul 21, 2012 06:16 PM

Forum Jump

All times are GMT -5. The time now is 04:07 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC