Search code examples
applescript

How do I get this apple script to pop up a dialog?


The following apple script times out. How do I get it to work?

This runs from inside a bash script and it's supposed to pop up a dialog. It works fine on one mac. But it times out on my computer. However, it start to work after I run the script once inside Apple's Script Editor. Also, if I run the Script Editor version before the script timeout, the dialog pops up! Is this a permissions issue? What is going on and how do I fix it?

Bash Script:

osascript <<EOT
    tell app "System Events"
        text returned of (display dialog "Enter value:" default answer "default" buttons {"OK"} default button 1 with title "Type A Value")
    end tell
EOT

Error:

46:159: execution error: System Events got an error: AppleEvent timed out. (-1712)

Solution

  • The display dialog command is not a System Events command. It is a Standard Additions command, therefore there is no need for a tell block

    Also, inserting an activate command before the display dialog command will ensure the dialog window will appear on top of any currently opened programs or windows.

    Try this...

    osascript <<EOT
        activate
        text returned of (display dialog "Enter value:" default answer "default" buttons {"OK"} default button 1 with title "Type A Value")
    EOT