Title: Re: Revised backup script
On or near 1/26/2001 2:58 AM, Jeff Porten at [EMAIL PROTECTED] observed:

> Sent this message a few days ago from the wrong account, and just noticed it
> bounced.  It addresses some of the problems raised on the list, but I
> haven’t incorporated any code to handle aliases in the Documents folder.
>
> Someone mentioned documentation; I’ve been much more fully documenting this
> in my ASC uploads.  Of course, they never seem to show up in the indexes, so
> God only knows if anyone’s been finding them.
>
> -----
>
> Totally rewrote the backup script I posted the other day to fix a bug in the
> logic, and incorporate the criticism I heard.  Since the first script was
> buggy, I'm posting the script again; you can also download from
> AppleScriptCentral.
>
Jeff,

Since I have relocated my Documents folder off my Startup Disk partition (to keep it small and to separate for backup purposes), your script as written fails for me, because of the hard-coded references to "startup disk". My way of relocating the Documents folder was just to move it to another drive and to place an alias for it on the startup disk. Therefore, what I needed was a version of your script (highly useful, by the way!) that would handle resolving the alias when necessary. This involved changing a dozen or more lines of your script, and of adding a different test for whether or not the backup folder(s) exist. For some reason, the "exists" verb would not work for me, so I substituted an "try/on error" block, which works fine and accomplishes the same purpose.

For those who want a version of Jeff's script that will find a relocated Documents folder via its alias, here it is. I would also post it on AppleScript Central, but since it is (other than the code to resolve the alias) really Jeff's script, I think I will let him do that. I don't care, Jeff, if you credit me or not for the alias code. No big deal.

If Jeff chooses not to post this revised version, just copy it from below:

tell application "Finder"
    activate
    
    set NewBackupNeeded to false
    set MyDisk to (path to startup disk) as string
    if MyDisk contains "Desktop folder:" then set MyDisk to text 1 thru (offset of ":" in MyDisk) of MyDisk
    set x to info for (MyDisk & "Documents:")
    if alias of x is true then
        tell application "Finder" to set oi to original item of alias file (MyDisk & "Documents:")
        set DocFolder to oi
        set MUD to ((DocFolder as string) & "Microsoft User Data:")
    else
        set DocFolder to alias MyDisk & "Documents:"
        set MUD to (MyDisk & "Documents:Microsoft User Data:")
    end if
    set OriginalFolder to alias MUD
    
    --Does a backup exist?
    set FirstBackupFolder to ((DocFolder as string) & "Microsoft User Data backup:") as file specification
    try
        get FirstBackupFolder as alias
        set FirstBackupExists to true
    on error
        set FirstBackupExists to false
    end try
    
    if FirstBackupExists then
        --Is a backup needed?
        set FirstBackupFolder to FirstBackupFolder as alias
        set NewBackupNeeded to (modification date of FirstBackupFolder < (current date) - 1 * days)
    end if
    
    --Does a second backup exist?
    set SecondBackupFolder to ((DocFolder as string) & "Microsoft User Data old backup:") as file specification
    try
        get SecondBackupFolder as alias
        set SecondBackupExists to true
    on error
        set SecondBackupExists to false
    end try
    
    if SecondBackupExists then
        set SecondBackupFolder to SecondBackupFolder as alias
    end if
    
    --Is Entourage running?
    set EntActive to (exists process "Microsoft Entourage")
    
    --Run the backup?
    set DoBackup to (NewBackupNeeded or (not FirstBackupExists))
    
    --Enough disk space?
    set DataSize to size of OriginalFolder
    set AvailSpace to free space of startup disk
    if DataSize > AvailSpace then
        display dialog "There is not enough disk space to make a backup." buttons {"OK"} default button {"OK"} with icon stop
        set DoBackup to false
    end if
    
    if DoBackup then
        if EntActive then
            set QuitEnt to display dialog "You are currently running Entourage.  OK to quit?" buttons {"Don't quit, postpone backup", "Quit and backup"} default button 2 with icon caution
            if button returned of QuitEnt is "Quit and backup" then
                tell application "Microsoft Entourage" to quit
            else
                set DoBackup to false
            end if
        end if
    end if
    
    if DoBackup then
        if SecondBackupExists then
            move SecondBackupFolder to trash
        end if
        
        if FirstBackupExists then
            set the name of FirstBackupFolder to "Microsoft User Data old backup"
        end if
        
        set NewBackup to make new folder at DocFolder with properties {name:"Microsoft User Data backup"}
        duplicate every item in OriginalFolder to NewBackup
    end if
    
    if EntActive and not (exists process "Microsoft Entourage") then
        tell "Microsoft Entourage"
            run
        end tell
    end if
    
end tell

--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to