Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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/"
share|improve this answer

Launchd agents are allowed to interact with the GUI, and even daemons can use osascript to display dialogs.

You could also use something like this in a shell script:

osascript -e 'tell app (path to frontmost application as text)'
display dialog "Continue?"
end' || exit 0

The script exits with an error if the user presses the cancel button or closes the dialog. You could also tell a background process like SystemUIServer to display the dialog, but you'd have to add something like activate application (path to frontmost application as text) to move focus back to the previously focused window.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.