0

The Apple Script repeats every minute when saved as an application and the box is checked as "stay open after run handler". I used this method to convert it to Shell Script: How do I convert this Applescript to Terminal osascript? , but it won't repeat as it does in the Apple Script. However it will work without the idle commands, but of course, it doesn't repeat. How do I get it to work? Is there a better syntax to use to have it repeat than #idle, #return 60 #end idle?

Apple Script

on idle
    tell application "Finder"
        if not (disk "Backup_Server" exists) then
            display alert "Backup_Server not found, please mount"
        end if
        delay 5
        if not (disk "Backup_Server" exists) then
            display alert "Backup_Server still not found, please submit a ticket"
            return 60
        end if
    end tell
end idle
on quit
    continue quit
end quit

Shell Script

#!/usr/bin/osascript
on idle
    tell application "Finder"
        if not (disk "Backup_Server" exists) then
            display alert "Backup_Server not found, please mount"
        end if
        delay 5
        if not (disk "Backup_Server" exists) then
            display alert "Backup_Server still not found, please submit a ticket"
            return 60
        end if
    end tell
end idle
on quit
    continue quit
end quit
1
  • You shouldn’t really be polling for the presence of a disk and definitely not with Finder (use System Events or, better yet, use the shell to test for it if polling is too irresistible). Instead, you can set up a monitor for the folder "/Volumes" folder to execute a script when the backup disk is present.
    – CJK
    Sep 21 '21 at 2:36
1

With an AppleScript script saved as a shell script you cannot use on idle, and return 60 unless you want return 60 to return 60

Use a repeat loop instead of an on idle handler, and replace return with delay.

The on quit handler is only good if you issued a quit command elsewhere in the code, otherwise you'd need to use ⌃C to quit the AppleScript shell script to break out of the repeat loop, unless you have coded a way out of it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .