|
|
#1 |
|
Prospect
Join Date: Aug 2004
Posts: 15
|
Help in UNIX
hi,
I think it is possible, but don't know how to do it!!! In a terminal: echo " Hello" will print Hello in the terminal. I am asking if it is possible to get a graphical window to say Hello instead of printing it in the terminal. Many thanks |
|
|
|
|
|
#2 |
|
Triple-A Player
Join Date: Mar 2004
Location: Behind you!! (London)
Posts: 54
|
you can use applescript
---- do shell script " echo Hello" display dialog result ---- |
|
|
|
|
|
#3 |
|
Prospect
Join Date: Aug 2004
Posts: 15
|
Thanks macg4dave,
But I am writting a script using UNIX, and need from UNIX to pop up this window... I don't kno if osascript can do that? Thank you
|
|
|
|
|
|
#5 |
|
Major Leaguer
Join Date: Feb 2004
Posts: 278
|
If you want to do it from a shell script, I believe osascript is just about your only option.
If you know how to use C, then check into CFUserNotification. |
|
|
|
|
|
#6 |
|
Prospect
Join Date: Aug 2004
Posts: 15
|
Thanks again macg4dave for help
|
|
|
|
|
|
#7 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
|
Here's an example of putting up a dialog (via AppleScript) from a shell script:
Code:
#!/bin/sh
# This script illustrates how to put up dialogs via AppleScript
# Note that some of the longer lines have been continued over two lines
# by typing a backslash immediately followed by a Return
# Cameron Hayne (macdev@hayne.net) December 2004
# a dialog with a text message and some buttons
message="Hello World!"
button=`osascript << EOT
tell application "Terminal"
say "$message"
beep
display dialog "$message" buttons {"Hello", "Goodbye"} \
default button "Hello" giving up after 15
set result to button returned of result
end tell
EOT`
echo "button was $button"
# a dialog with a text message, a textfield, and one button
message="What is your name?"
defName="Fred"
name=`osascript << EOT
tell application "Terminal"
say "$message"
beep
display dialog "$message" buttons {"OK"} default answer "$defName" \
default button "OK"
set result to text returned of result
end tell
EOT`
echo "name: $name"
|
|
|
|
|
|
#8 | |||||||||||||||||||
|
Triple-A Player
Join Date: Nov 2003
Location: Yakima, Wa.
Posts: 93
|
I've got the perfect solution for you! You want a program called cocoadialog. It's free from sourceforge and it allows you to throw up nice aqua dialogs with or without buttons and text inputs from shell scripts or php or perl or whatever. Heres an example of a shell script that throws a dialog
You can get it here: http://cocoadialog.sourceforge.net/ It6's really cool I use it all the time for simple gui's for some php cli scripts that I wrote. |
|||||||||||||||||||
|
|
|
|
|
#9 |
|
Prospect
Join Date: Aug 2004
Posts: 15
|
Thank you ezmobius.. I am using Pashua:
http://www.bluem.net/downloads/pashua_en/ If you know it, can you please tell me if cocoadialog is better or not?..Thanks |
|
|
|
|
|
#10 |
|
Triple-A Player
Join Date: Nov 2003
Location: Yakima, Wa.
Posts: 93
|
I personally like cocoa dialog better. It seemed to have more options than pashua, but I admit that I haven't tried Pashua in a long time so maybe it's gotten better? Anyway cocoa dialog lets you make many different types of dialogs, including: timed warnings like just pop up a dialog with something you want to say to your user and then have the dialog automatically dissapear after x amount of sedconds. Or diaalogs with as manyt buttons as you want. Or the one I use a lot is the single line or many line text input dialog. Plus cocoa dialog has wrappers available for 5 or 6 different scripting languages. It's worth checking out at least.
|
|
|
|
|
|
#11 |
|
Prospect
Join Date: Dec 2004
Posts: 4
|
I just tried CocoaDialog, it works great. Thanks a lot for this one, it solved me a problem!
|
|
|
|
|
|
#12 |
|
Prospect
Join Date: Jan 2002
Posts: 6
|
If anyoen is interested, I have written a more AppleScript-like front end for Pashua and for ProgBar (displaying progress bars).
send me an email (or post) for more information. |
|
|
|
|
|
#13 |
|
Prospect
Join Date: Aug 2004
Posts: 15
|
Hi ezmobius,
Thanks for your comments... In fact, I downloaded cocoaDialog but I don't know how it works !!! Can you please tell me how to run one example (.sh) in a terminal?? Thanks |
|
|
|
|
|
#14 |
|
Triple-A Player
Join Date: Nov 2003
Location: Yakima, Wa.
Posts: 93
|
Sure-
Heres a great page with plenty of examples for shell scripts, perl, and even php scripts. It shows how to pop-up many different types of dialogs and how to read back in what button was pushed or what text was entered. http://cocoadialog.sourceforge.net/examples.html |
|
|
|
|
|
#15 |
|
Prospect
Join Date: Aug 2004
Posts: 15
|
Dear ezmobius,
Sorry, may be my question was not clear. I saw the examples page, but I ask about the command line that I have to write in a terminal to run this examples. For example, using Pashua, in a terminal, I write: ./example.sh where example.sh file exists in the folder of Examples , and it works fine.. ![]() Thanks |
|
|
|
|
|
#16 | |||||||||||||||||||
|
Triple-A Player
Join Date: Nov 2003
Location: Yakima, Wa.
Posts: 93
|
Ok heres the scoop on how to make it happen. Make sure that you install cocoadialog in you /Applications folder without being in a folder of it's own. Just the app inside the Applications folder. Then copy this script:
In your terminal type: pico test.sh Once pico opens up then you want to paste in the above script. Now hit ctrl-o and return to save then hit ctrl-x to exit. Now you need to make it executable: chmod +x test.sh Now you should be able to run it like this: ./test.sh Hope that answers you questions. On the examples page, they assume that you installed cocoadialog in ~/Applications but I like to put it in the main /Applications folder. So if you use any more of the examples from that page then you need to change the line: CD="$HOME/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" To: CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" Other than that it should work fine! |
|||||||||||||||||||
|
|
|
|
|
#17 |
|
Prospect
Join Date: Aug 2004
Posts: 15
|
it's Fine..
![]() it works now, thanks a lot... My problem was with this line: CD="$HOME/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" Here you are the results: ![]() [6:37pm MyMac ~/Desktop/temps]% ./test.sh User pressed the Yes button User likes this program [6:38pm MyMac ~/Desktop/temps]% Thanks again |
|
|
|
|
|
#18 |
|
Triple-A Player
Join Date: Aug 2002
Posts: 70
|
I need some help with cocoadialog. Using the script:
#!/bin/bash CD="$HOME/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" ### Find file or directory and open rv=`$CD fileselect \ --text "Pick some files and/or directories" \ --with-directory $HOME/ \ --select-directories \ --select-multiple` if [ -n "$rv" ]; then ### Loop over lines returned by fileselect echo -e "$rv" | while read file; do ### Check if it's a directory if [ -d "$file" ]; then echo "Directory: $file" Else a regular file elif [ -e "$file" ]; then echo "Regular file: $file" fi done else echo "No files chosen" fi open $rv ___________________________________________________________ cocoadialog opens a single name file ('test') just fine. But how can I get it to open a multiname file ('test file')? Thanks, bjast |
|
|
|
|
|
#19 |
|
Triple-A Player
Join Date: Jun 2004
Posts: 77
|
Try quoting $rv when using it with the open command:
open "$rv" Steve |
|
|
|
|
|
#20 |
|
Triple-A Player
Join Date: Aug 2002
Posts: 70
|
Thanks!
That did the job. But how come it did the job? bjast |
|
|
|
![]() |
|
|