You can specify a background process, such as SystemUIServer, to display a dialog box. A previously focused window does not return focus after closing the default dialog box. System events and AppleScript Runner may have slight delays if they have not been executed 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 can also say that the application on the front panel displays a dialog box, but it is often a bit slower. The dialog is not displayed immediately if the application does not respond. If MPlayer OS X is in front, text dialogs do not 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
source share