launchd: ask user before performing tasks
Solution 1:
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)
try
set dialogResult to display dialog "Do you want to execute?" default button 2 giving up after timeoutInSeconds
on error number -128
return
end try
end tell
if gave up of dialogResult and abortOnTimeout then
return
end if
do shell script "/path/to/yourscript.sh"
Solution 2:
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.