![]() |
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 |
you can use applescript
---- do shell script " echo Hello" display dialog result ---- |
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 :) |
What about NStask (See here ) for more info. But you do have to make it in C.
|
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. |
Thanks again macg4dave for help :)
|
Here's an example of putting up a dialog (via AppleScript) from a shell script:
Code:
#!/bin/sh |
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:
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. |
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 |
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.
|
I just tried CocoaDialog, it works great. Thanks a lot for this one, it solved me a problem!
|
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. |
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 |
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 |
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 |
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:
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! |
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 |
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 |
Try quoting $rv when using it with the open command:
open "$rv" Steve |
Thanks!
That did the job. But how come it did the job? bjast |
When you quoted the variable it expands to look like this if you had selected a 2 name file with a space:
'file name' This 'hides the space from the command line. So your script works. Whenever you write scripts that have variables that might expand into strings with spaces or weird characters. This way no matter what you throw at the script(within reason) will still be handled as you intended. |
That's a very helpful insight!
Thanks, bjast |
Bash, inputbox, and variable
I haven't been able to find anything in this forum, the CocoaDialog
documentation, or on the web about setting variables in a shell script through user input and then working with the data. I'd like to be able to take user input via an inputbox or standard-inputbox in a shell script and set a variable without the button information embedded in the variable. Can anyone explain to me how to do this? I was able to use the Perl examples for a standard-inputbox and inputbox to set a variable, but here's my problem. The variable is set, but the first line of the variable has the number of the button that was pressed and then the input data (the data I really care about) is stuck on the second line of the variable. How do I set the variable so that just the input data is contained? Does the shell have a way to split data up like Perl does? Maybe I need to use pipes... Maybe I need to look at more shell examples on the web? |
| All times are GMT -5. The time now is 06:00 PM. |
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.