I tried to call a simple messagebox from the console using:
osascript -e "display dialog \"hello\""
but it returns:
execution error: No user interaction allowed. (-1713)
Is there a workaround?
EDIT:
The workaround is: tell application "AppleScript Runner" to display dialog "Hello"
You can tell a background process like SystemUIServer to display the dialog. The previously focused window doesn't get focus back after the dialog is closed by default. System Events and AppleScript Runner might have small delays if they weren't running before.
answer=$(osascript -e 'try
tell application "SystemUIServer"
set answer to text returned of (display dialog "" default answer "")
end
activate app (path to frontmost application as text)
answer
end' | tr '\r' '\n')
[[ -z "$answer" ]] && exit
You could also tell the frontmost application to display a dialog, but it's often slightly slower. The dialog isn't shown immediately if the application is not responding. If MPlayer OS X is frontmost, text dialogs don't accept any keyboard input.
answer=$(osascript -e 'try
tell application (path to frontmost application as text)
text returned of display dialog "" default answer ""
end
end' | tr '\r' '\n')
[[ -z "$answer" ]] && exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With