Re: [Cocoadialog-users] Bourne Shell Script Equivalent to Perl Script Sample for CocoaDialog Dropdo
Status: Beta
Brought to you by:
sporkstorms
From: Bill L. <wl...@sw...> - 2008-12-01 11:14:04
|
On Nov 30, 2008, at 11:44 PM, Thomas Patko wrote: > Hello Bill: > > Thank you very much for the Bourne shell script code and concept. I > agree that it is not necessarily the most elegant approach but the > combination of --no-newline and the awk '{print $X}' code reliably > script out the multiple variables passed back by CocoaDialog. I > have made it work quite well for my application, wherein I was only > really interested in the second variable. An alternative, without using "awk", and having a "case...esac" statement to display the selected answer: #!/bin/sh CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" result=`$CD dropdown \ --title "Preferred OS" \ --items "Mac OS X" "GNU/Linux" "Windows" \ --button1 "That one!" \ --button2 Nevermind` return=`echo $result | cut -d" " -f1` answer=`echo $result | cut -d" " -f2` if [ $return -eq 1 ]; then case $answer in 0) echo "Mac OS X";; 1) echo "GNU/Linux";; 2) echo "Windows";; esac else echo "Nevermind" fi The "--no-newline" really isn't necessary. I originally included it because the original Perl script had it there. I am using "cut" to parse the output rather than "awk". My complaint with using "awk" is that it is a fairly heavy handed approach to a problem. It is great when you need to do a lot of processing of the input but has a tremendous amount of overhead to use when the processing is quite simple. I'm actually very impressed to see that someone is USING this mailing list. The inactivity on this list implies that not much is happening with CocoaDialog, which I'm glad to see isn't totally correct. |