Create bookmarks on startup?

Discussion in 'Mac Programming' started by Sinergi, Jun 13, 2012.

  1. macrumors newbie

    Joined:
    May 8, 2011
    #1
    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!
     
  2. kryten2, Jun 13, 2012
    Last edited: Jun 13, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    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 :

    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
     
  3. Sinergi, Jul 3, 2012
    Last edited: Jul 3, 2012

    thread starter macrumors newbie

    Joined:
    May 8, 2011
    #3
    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?
     
  4. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    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"

    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"
     
  5. thread starter macrumors newbie

    Joined:
    May 8, 2011
    #5
    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
     
  6. macrumors newbie

    Joined:
    Jun 27, 2008
    Location:
    Cape Town, South Africa
    #6
    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 '~'.
     
  7. kryten2, Jul 4, 2012
    Last edited: Jul 4, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium

Share This Page