Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

bash - dialog box

Hello.

Such question beguile :

if possible creation of dialog window is in terminal

#!/bin/bash
dialog --title " yesno" \
--backtitle "script" \
--yesno "yes no" 5 30

If so, then it is necessary to install that program ?
Do some ) www pages be with description ?

thank for assistance and I salute.

Posted on Feb 17, 2006 6:33 AM

Reply
2 replies

Feb 17, 2006 7:21 AM in response to zielony

I am not sure if this is exactly what you are asking for but here is a code fragment that will work in the bash shell.

a=$( osascript \
-e 'tell application "Finder"' \
-e 'activate' \
-e 'set dialog_result to display dialog "yesno" with title "script" buttons {"yes","no"}' \
-e 'end tell' \
-e 'tell application "Terminal"' \
-e 'activate' \
-e 'end tell' \
-e 'get button returned of dialog_Result'
)
echo $a

The variable a will contain the name of the button pressed in the dialog.

This requires no third party programs to be installed. osascript is a program included by apple with OS X. See "man osascript" for more information about it.

Hope this helps.

Feb 17, 2006 10:10 AM in response to Curtis Brown

here is a code fragment that will work in the bash shell.


Just be aware that this will not work on a remote shell. It uses osascript to display the dialog (after trying to activate the Finder for some reason), but if you're logged into a remote machine it's going to run osascript on that remote machine and try to get the remote Finder (if it's even running) to display the dialog.

If you're only running this script locally you might be OK (although I'd still get rid of the activate Finder/activate Terminal elements), but don't try it remotely.

If you need a 'pure' shell solution that interacts with the user, you're pretty much limited to either using 'read' to capture user input at the command line, or some fancy $TERM scripting to build a UI using terminal control codes.

bash - dialog box

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.