Hi all
looking for some help with a script. (I’m new at scripting)
This is an automated backup script using rsync. I’ve pasted only the last (and relevant) portion of the script below. I added the opening 'tell application “finder” tag so that it looks normal. There’s a couple more blocks above what I posted, (within the tell finder tag) but they work fine, so I didn’t include them. There’s also a couple set statements that set the path and disk of the variables ‘a’ and ‘b’. They’re outside of the opening ‘tell finder’ tag, at the very top of the script.
The problem I’m stumped on is that when the script reaches the end of the checking destination part, if the destination is not there, it’s supposed to write to the log, display the dialog (it works fine to this point) and then quit once the dialog is answered. (tell me - quit - end tell within the if statement.) Instead of quitting, it goes on to run the next portion of the script - the part that runs rsync. It does this once I click one of the dialog buttons. I’ve tried changing around the blocks of the script, and even though the code is the same as the other blocks, it only happens on the last section before the rsync portion. According to the logs, (and from what I can see on screen) when you click to dismiss the dialog on the ‘check for destination’ part, it skips over the following 'tell me - quit - end tell" block (it shouldn’t) and skips the ‘else’ block (like it should) and goes on to the ‘try’ block, runs rsync, gets an error (from rsync - destination not found), writes the error to the log, displays the error dialog from the rsync section, and then quits immediately without waiting for the user to click a button.
If I enclose the rsync portion of the code within the end tell (finder) tag, it works as expected, but it hangs up the finder until the backup is complete.
first, what’s going on, 'cause I can’t see what’s wrong! I’m sure I’m overlooking something, but I just can’t see it.
I wouldn’t mind rsync running within the ‘tell finder’ tags, if it didn’t hog up finder. If the only fix is enclosing rsync in the finder tags, Is there a way to forcce it to run in the background so it doesn’t make finder appear to be hung?
Thanks in advance for any help - it’s appreciated. I’ve gotten this far on my own, but I don’t even know what to do about this one.
Here’s the code. I can paste the entire script if needed.
tell application "Finder"
--check for destination path
if (folder b of disk a exists) = false then
do shell script "logger -s Backup: Destination path not found: Backup canceled."
activate
display dialog "There was a problem backing up your files. Please see the log for details." with icon 2 buttons {"Show Log", "OK"} default button 2
if button returned of result is "show log" then
tell application "Console"
open "/var/log/system.log"
activate
end tell
end if
tell me
quit
end tell
else
do shell script "logger -s Backup: Destination path OK. Performing backup."
end if
end tell
--perform backup
try
do shell script "rsync -ac --delete /foo/bar /Volumes/jezebel/Archive/Backup"
on error errMsg
do shell script "logger -is Backup: Error reported by rsync:" & quoted form of errMsg & ": Backup canceled."
activate
display dialog "There was a problem backing up your files. Please see the log for details." with icon 2 buttons {"Show Log", "OK"} default button 2
if button returned of result is "show log" then
tell application "Console"
open "/var/log/system.log"
activate
end tell
end if
tell me
quit
end tell
end try
do shell script "logger -s Backup: Completed sucessfully."
tell application "Finder"
activate
display alert "Your files have been backed up."
end tell