Getting a Script to Stop

I have a backup application I’m trying to run via the script below:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "SyncTime" to activate

tell application "SyncTime"
	run sync group "Local Backups"
	delay 30
	tell application "SyncTime" to quit
end tell

The script runs, the SyncTime application performs the backup and then quits. But the script itself just keeps on running, and running, and running (in Script Debugger).

What do I need to add to this script to have it terminate. I have not tried to create an AppleScript application and run it via that.

Just tried running via AppleScript application, and same result. Everything runs/happens just fine, but the AppleScript application just sits in the Dock until I right click on the icon and select “Quit.”

I’ve stumbled upon a solution. I’ve added this line to the end of the script:

tell application "System Events" to key code 46 using {command down}

Seems to work, but if someone has a more elegant solution (I’m an AppleScript novice) I’m all ears.

Not critical (and I don’t think it’s the cause of your problem), but you have three separate ‘tell application “SyncTime”’ statements, including one embedded within the other. You only need one - all of these commands can be run in a single tell block.

That said, without having SyncTime installed it’s hard to test. My guess would be that the run sync group command is taking longer than you expect and that AppleScript is waiting for it to finish. TBH, that’s about the only failure condition I can see since the rest of the code is pretty vanilla.

So the question is - does run sync group actually complete?

You can test this by adding some logging or other intrusive commands, such as:

tell application "SyncTime"
    activate -- may not be necessary?
    display dialog "Starting run..."
    run sync group "Local Backups"
    display dialog "Finished run... pausing"
    delay 30 -- not sure why you think you need this delay here?
    display dialog "done waiting... quitting"
    quit
end tell

When you run it, it should be pretty clear how far the script gets.

Looking at it, the big question is whether AppleScript waits for the run sync group to finish before continuing, which would be the normal behaviour. I don’t see the value of the delay afterward, unless you think you need to add this for the backup to finish…?

I went on SyncTime’s help website.
https://desairem.com/wordpress/synctime-control-synctime-with-applescript/
They had a sample script that showed a command to wait for syncing to finish.

tell application "SyncTime"
    run sync item "Documents Backup"
    run sync group "Home"
    once all syncs are completed "Sleep"
end tell

Thanks for the help Camelot and Robert, but I’ve given up on this backup application. It seems to have a few quirks that are beyond my ability to solve.

Besides, I have this “thing” for backup applications. I already use Carbon Copy Cloner, ChronoSync, Sync Folders Pro and a couple of Rsync routines that I wrote myself, so I’m pretty well covered. Like I said, it’s a “thing”.