Posted on Sun - November 13, 2005

Time folder restore


Here is the sibling script to the backup time folder. It is not totally automated, you have to drag the xfer folder created by the other script to the desktop. Since I usually work from a disk image or an archive, it works for me.

After you run this script, you should log out and log back in so the applications don't try to use the trashed files.

It's pretty obvious but I will walk you through it.

First the script checks to see if something is there on the desktop to be transfered. This whole script is a series of nesting if/then statements, so at first glance things may look a little out of order.
tell application "Finder"
activate
if folder "Users:neo:Desktop:xfer" exists then

I don't like major changes happening without my permission, so up comes a dialogue before deleting files.
display dialog "Are you sure? This will overwrite your existing project files." buttons {"NEVER", "Go for it!"} default button "NEVER"
set XferState to (button returned of result)
if XferState is "Go for it!" then


You have to have the script test that the file exists before deleting, otherwise the script will hang when it tries to delete a nonexistent file.
if folder "Users:neo:Projects" exists then
delete "Users:neo:Projects"
end if
duplicate folder "Users:neo:Desktop:xfer:Projects" to folder "Users:neo"
if folder "Users:neo:Library:Safari" exists then
delete folder "Users:neo:Library:Safari"
end if
duplicate folder "Users:neo:Desktop:xfer:Safari" to folder "Users:neo:Library"
if folder "Users:neo:Library:Scripts" exists then
delete folder "Users:neo:Library:Scripts"
end if
duplicate folder "Users:neo:Desktop:xfer:Scripts" to folder "Users:neo:Library"
if folder "Users:neo:Documents:Palm" exists then
delete folder "Users:neo:Documents:Palm"
end if
duplicate folder "Users:neo:Desktop:xfer:Palm" to folder "Users:neo:Documents"
if folder "Users:neo:Library:Application Support:iBlog" exists then
delete folder "Users:neo:Library:Application Support:iBlog"
end if
duplicate folder "Users:neo:Desktop:xfer:put in library-application support:iBlog" to folder "Users:neo:Library:Application Support"
if file "Users:Neo:Library:Preferences:com.lifli.iBlog.plist" exists then
delete file "Users:Neo:Library:Preferences:com.lifli.iBlog.plist"
end if
duplicate file "Users:neo:Desktop:xfer:put in library-preferences:com.lifli.iBlog.plist" to folder "Users:Neo:Library:Preferences"
if folder "Users:neo:Sites:iBlog" exists then
delete folder "Users:neo:Sites:iBlog"
end if
duplicate folder "Users:neo:Desktop:xfer:iBlog" to folder "Users:neo:Sites"
if folder "Users:neo:Pictures:webgrfx" exists then
delete folder "Users:neo:Pictures:webgrfx"
end if
duplicate folder "Users:neo:Desktop:xfer:webgrfx" to folder "Users:neo:Pictures"
if folder "Users:neo:Sites:neowaylanddotnet" exists then
delete folder "Users:neo:Sites:neowaylanddotnet"
end if
duplicate folder "Users:neo:Desktop:xfer:neowaylanddotnet" to folder "Users:neo:Sites"
if folder "Users:neo:Sites:frame pages" exists then
delete folder "Users:neo:Sites:frame pages"
end if
duplicate folder "Users:neo:Desktop:xfer:frame pages" to folder "Users:neo:Sites"


Then the script cleans up after itself.
delete folder "Users:neo:Desktop:xfer"
say "All files updated."


Now to deal with the uncompleted if/then statements. The next one is the response to the dialogue box.
else
say "Canceling updates"
end if

And the last one (which was actually the first question asked) was the test to see if the folder xfer existed on the desktop.
else
say "Nothing on the desktop to transfer"
end if
end tell

And that is it. Here is the whole script in a block.
tell application "Finder"
activate
if folder "Users:neo:Desktop:xfer" exists then
display dialog "Are you sure? This will overwrite your existing project files." buttons {"NEVER", "Go for it!"} default button "NEVER"
set XferState to (button returned of result)
if XferState is "Go for it!" then
if folder "Users:neo:Projects" exists then
delete "Users:neo:Projects"
end if
duplicate folder "Users:neo:Desktop:xfer:Projects" to folder "Users:neo"
if folder "Users:neo:Library:Safari" exists then
delete folder "Users:neo:Library:Safari"
end if
duplicate folder "Users:neo:Desktop:xfer:Safari" to folder "Users:neo:Library"
if folder "Users:neo:Library:Scripts" exists then
delete folder "Users:neo:Library:Scripts"
end if
duplicate folder "Users:neo:Desktop:xfer:Scripts" to folder "Users:neo:Library"
if folder "Users:neo:Documents:Palm" exists then
delete folder "Users:neo:Documents:Palm"
end if
duplicate folder "Users:neo:Desktop:xfer:Palm" to folder "Users:neo:Documents"
if folder "Users:neo:Library:Application Support:iBlog" exists then
delete folder "Users:neo:Library:Application Support:iBlog"
end if
duplicate folder "Users:neo:Desktop:xfer:put in library-application support:iBlog" to folder "Users:neo:Library:Application Support"
if file "Users:Neo:Library:Preferences:com.lifli.iBlog.plist" exists then
delete file "Users:Neo:Library:Preferences:com.lifli.iBlog.plist"
end if
duplicate file "Users:neo:Desktop:xfer:put in library-preferences:com.lifli.iBlog.plist" to folder "Users:Neo:Library:Preferences"
if folder "Users:neo:Sites:iBlog" exists then
delete folder "Users:neo:Sites:iBlog"
end if
duplicate folder "Users:neo:Desktop:xfer:iBlog" to folder "Users:neo:Sites"
if folder "Users:neo:Pictures:webgrfx" exists then
delete folder "Users:neo:Pictures:webgrfx"
end if
duplicate folder "Users:neo:Desktop:xfer:webgrfx" to folder "Users:neo:Pictures"
if folder "Users:neo:Sites:neowaylanddotnet" exists then
delete folder "Users:neo:Sites:neowaylanddotnet"
end if
duplicate folder "Users:neo:Desktop:xfer:neowaylanddotnet" to folder "Users:neo:Sites"
if folder "Users:neo:Sites:frame pages" exists then
delete folder "Users:neo:Sites:frame pages"
end if
duplicate folder "Users:neo:Desktop:xfer:frame pages" to folder "Users:neo:Sites"
delete folder "Users:neo:Desktop:xfer"
say "All files updated."
else
say "Canceling updates"
end if
else
say "Nothing on the desktop to transfer"
end if
end tell

www.teknopagan.com
       



teknologi
© 2005 - 2008 All Rights Reserved