Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 12-02-2004, 04:43 AM   #1
Abd73fr
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
Abd73fr is offline   Reply With Quote
Old 12-02-2004, 05:25 AM   #2
macg4dave
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
----
macg4dave is offline   Reply With Quote
Old 12-02-2004, 05:49 AM   #3
Abd73fr
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
Abd73fr is offline   Reply With Quote
Old 12-02-2004, 06:06 AM   #4
macg4dave
Triple-A Player
 
Join Date: Mar 2004
Location: Behind you!! (London)
Posts: 54
What about NStask (See here ) for more info. But you do have to make it in C.
macg4dave is offline   Reply With Quote
Old 12-02-2004, 08:54 AM   #5
huskerchad
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.
huskerchad is offline   Reply With Quote
Old 12-02-2004, 08:57 AM   #6
Abd73fr
Prospect
 
Join Date: Aug 2004
Posts: 15
Thanks again macg4dave for help
Abd73fr is offline   Reply With Quote
Old 12-02-2004, 11:24 AM   #7
hayne
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"
hayne is offline   Reply With Quote
Old 12-02-2004, 05:25 PM   #8
ezmobius
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

Quote:
#!/bin/bash

CD="$HOME/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog"

rv=`$CD ok-msgbox --text "We need to make sure you see this message" \
--informative-text "(Yes, the message was to inform you about itself)" \
--style critical --no-newline`
if [ "$rv" == "1" ]; then
echo "User said OK"
elif [ "$rv" == "2" ]; then
echo "Canceling"
exit
fi

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.
ezmobius is offline   Reply With Quote
Old 12-03-2004, 11:14 AM   #9
Abd73fr
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
Abd73fr is offline   Reply With Quote
Old 12-03-2004, 02:35 PM   #10
ezmobius
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.
ezmobius is offline   Reply With Quote
Old 12-04-2004, 04:20 AM   #11
ettorep
Prospect
 
Join Date: Dec 2004
Posts: 4
Thumbs up

I just tried CocoaDialog, it works great. Thanks a lot for this one, it solved me a problem!
ettorep is offline   Reply With Quote
Old 12-08-2004, 04:55 PM   #12
DeltaTee
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.
DeltaTee is offline   Reply With Quote
Old 12-09-2004, 05:28 AM   #13
Abd73fr
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
Abd73fr is offline   Reply With Quote
Old 12-09-2004, 10:55 AM   #14
ezmobius
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
ezmobius is offline   Reply With Quote
Old 12-09-2004, 11:21 AM   #15
Abd73fr
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
Abd73fr is offline   Reply With Quote
Old 12-09-2004, 11:37 AM   #16
ezmobius
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:
Quote:
#!/bin/bash

CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog"

### Example 1
rv=`$CD yesno-msgbox --no-cancel --string-output --no-newline \
--text "This is a simple first example" \
--informative-text "We're just going to echo the string output"`
echo "User pressed the $rv button"

### Example 2
rv=`$CD yesno-msgbox --text "Do you like CocoaDialog?"`
if [ "$rv" == "1" ]; then
echo "User likes this program"
elif [ "$rv" == "2" ]; then
echo "User does not like this program"
elif [ "$rv" == "3" ]; then
echo "User has no opinion (pressed cancel)"
fi

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!
ezmobius is offline   Reply With Quote
Old 12-09-2004, 12:39 PM   #17
Abd73fr
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
Abd73fr is offline   Reply With Quote
Old 12-12-2004, 11:20 PM   #18
bjast
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
bjast is offline   Reply With Quote
Old 12-13-2004, 10:48 AM   #19
hermasj
Triple-A Player
 
Join Date: Jun 2004
Posts: 77
Try quoting $rv when using it with the open command:

open "$rv"

Steve
hermasj is offline   Reply With Quote
Old 12-13-2004, 08:10 PM   #20
bjast
Triple-A Player
 
Join Date: Aug 2002
Posts: 70
Thanks!

That did the job. But how come it did the job?

bjast
bjast is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 02:58 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.