Launchd: ask user before performing tasks


Is there a way to get a user-defined launchd task (i.e. like the one in this question) to get user confirmation before executing the task? A popup like the one for scheduled sleep (with yes/no and a timer in case of no user input) would be great, otherwise a simple yes/no popup would work.

Best Answer

  • Make launchd call this AppleScript. It displays a dialog with a timeout and calls a shell script if the user selected "Ok".

    set timeoutInSeconds to 60
    set abortOnTimeout to true
    tell application (path to frontmost application as text)
            set dialogResult to display dialog "Do you want to execute?" default button 2 giving up after timeoutInSeconds
            on error number -128
        end try
    end tell
    if gave up of dialogResult and abortOnTimeout then
    end if
    do shell script "/path/to/"
  • Related Question