Couple questions
--17.09.2011 hubionmac.com
-- Prefs-Save-Restore_v1: Saves and Restores an app's preferences, Library Folder, Application Support Folder using a tar archive
-- inspired by http://macscripter.net/viewtopic.php?id=37052
-- STORE THIS AS AN APPLICATION OR SCRIPT BUNDLE!!!!
global store_here
--first get the folder where all the saved prefs should be saved..
try
set store_here to quoted form of POSIX path of (path to resource "saved_prefs")
on error msg
do shell script "mkdir " & quoted form of POSIX path of (path to me as alias) & "Contents/Resources/saved_prefs"
--NOT USING PATH TO RESSOURCE BECAUSE IT DOESN'T SEEM TO UPDATE THAT FAST..
set store_here to quoted form of POSIX path of (path to me as alias) & "Contents/Resources/saved_prefs"
end try
-- WHAT TO DO?
set theaction to button returned of (display dialog "Do you want to restore or backup an app Prefs?" buttons {"Restore", "Backup", "Cancel"} default button {"Restore"})
if theaction = "Backup" then
make_backup(choose file of type "app")
else if theaction = "Restore" then
make_restore()
end if
From my understanding, this section contains the user interface, as well, it also sets the location of the app preferences to be restored, correct?
on make_restore()
set thebackups to every paragraph of (do shell script "ls " & store_here)
if thebackups = {} then
error "There are no backups that can be used to restore.."
else
set t to (choose from list thebackups with prompt "Choose one or more backup(s):" default items (item 1 of thebackups) with multiple selections allowed)
if t ≠false then
repeat with m in t
do shell script "cd ~/Library; tar xf " & store_here & quoted form of m
my display_message("Restored " & m & ".", 2)
end repeat
end if
end if
end make_restore
This part copies the user back up into the user library?
on make_backup(this)
set search_folders to {"./", "'Application Support'/", "Preferences/"}
tell application "Finder"
--GET THE IMPORTANT INFOS OUT OF INFO.PLIST FOR GETTING THE NAMES OF PLIST AND OTHER FILES AND FOLDERS INSIDE THE LIBARAY
set this_info_plist to quoted form of POSIX path of (item "Info.plist" of folder "Contents" of this as alias)
set this_id to do shell script "defaults read " & this_info_plist & " CFBundleIdentifier"
set this_bundleName to do shell script "defaults read " & this_info_plist & " CFBundleName"
--THIS LOOKS COMPLICATED BUT IS FASTER THAN USING THE FINDER
--AND IS IS THAT COMPLICATED BECAUSE OF THE OUTPUT OF THE FIND COMMAND THAT NEEDS TO BE QUOTED ;-/
set this_app_files to {}
repeat with search_folder in search_folders
--SEARCH THE SEARCH_FOLDER FOR FILES AND FOLDERS BUT ONLY ON THE FIRST LEVEL!!!
set tmp to every paragraph of (do shell script "cd ~/Library/" & search_folder & "; find . -maxdepth 1 -name '" & this_id & "*' -exec basename {} \\;")
repeat with t in tmp
set this_app_files to this_app_files & ((search_folder & quoted form of t) as text)
end repeat
set tmp to every paragraph of (do shell script "cd ~/Library/" & search_folder & "; find . -maxdepth 1 -name '" & this_bundleName & "' -exec basename {} \\;")
repeat with t in tmp
set this_app_files to this_app_files & ((search_folder & quoted form of t) as text)
end repeat
end repeat
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set this_app_files to this_app_files as text
set AppleScript's text item delimiters to old_delimiters
--NOW MAKE A TAR FILE OF ALL THESE IN THIS APPS RESSOURCE FOLDER
do shell script "cd ~/Library/; tar -czf " & store_here & this_id & ".tar.gz " & this_app_files
my display_message("Stored " & this_id & ".", 2)
end tell
end make_backup
This part of the script seems to be non functional,
Error Message
With the options, Edit, and, OK
When I open safaris info.plist I find the string CFBundleIdentifier
Anyone understand how this functions and how to make it work?
on display_message(msgTXT, msgTimeout)
tell application "System Events"
set isRunning to ¬
(count of (every process whose name is "GrowlHelperApp")) > 0
end tell
if isRunning = true then
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Status"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to ¬
{"Status"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"Finder" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Finder"
-- Send a Notification...
notify with name ¬
"Status" title ¬
"Prefs-Safe-Restore" description ¬
msgTXT application name ¬
"Finder"
return true
end tell
else
activate
display dialog msgTXT giving up after msgTimeout
end if
end display_message[/applescript
This section has semantic errors when I attempt to run it.