Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppleScript returns "No user interaction allowed" [duplicate]

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"

like image 710
blez Avatar asked Aug 08 '12 18:08

blez


1 Answers

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
like image 130
Lri Avatar answered Nov 20 '22 18:11

Lri