-- Xcode 4 Bookmarks-Restore
-- Version 1.0 Bill Cheeseman 2011-08-08
property xcodePrefsPath : (path to preferences as string) & "com.apple.dt.Xcode.plist"
property bookmarksKey : "kDSMBookmarkManagerAllBookmarksUserDefaultsKey"
if running of application "Xcode" then
activate
display alert "Xcode is running" message "Quit Xcode and run the Restore Xcode 4 Bookmarks script again" buttons {"OK"} default button "OK"
return
end if
tell application "System Events"
get (exists property list item bookmarksKey of property list file xcodePrefsPath)
if result is false then
set newPrefsItem to {|kDSMBookmarkManagerAllBookmarksUserDefaultsKey|:{}}
tell contents of property list file xcodePrefsPath
set originalValue to value
set value to originalValue & newPrefsItem
end tell
end if
end tell
activate
set bookmarksFile to choose file with prompt "Restore Xcode 4 bookmarks from:" default location (path to desktop)
set fileRef to open for access bookmarksFile
try
set bookmarks to read fileRef as list
tell application "System Events" to set value of property list item bookmarksKey of property list file xcodePrefsPath to bookmarks
close access fileRef
on error errMsg number errNum
close access fileRef
activate
display alert "Error " & errNum message errMsg
end try