|
#1
| |||
| |||
| open (Terminal) shell scripts by double-click
Here's a neat trick: If you use shell scripts, such as: #!/bin/sh <your shell script here> you can actually make them double-clickable from Finder, so they *almost* work like fully-fledged Applications. You will need to be an administrative user to do these things: - Create your shell script, with an editor that won't include extra characters (eg. pico in Terminal). - In Terminal, make that script executable, eg. w/ chmod a+x <yourscriptname> This will all be known to Terminal-savvy users so far. But now: - In Finder, locate the script and select Get Info (command-I) on it. - Select Open With: Other... - Change from Recommended Applications to All Applications. - Browse to /Applications/Utilities and select Terminal. - DO NOT select the Always Open With checkbox (unless you expressly want to associate a certain file extension with Terminal -- really this would be a Very Bad Thing). - After clicking Ok and closing Get Info, you should be able to simply double-click on the file in question from Finder and what will happen is, Terminal will open up and execute that very script. If your script is non-interactive, ie. if it will just do something and then exit, the Terminal session will be finished as well (ie. you can't go on and type in further commands at the prompt). By default, the shell window will however stay open, allowing you to review any output from your script. Also, the actual Terminal application will NEVER quit automatically (though this is not much of a problem). There is one potential cosmetic problem: If there is any output from your script, that will possibly already start to get written to the window while the initial shell prompt is still being written. This again is only a cosmetic problem in that it can jumble up what effectively gets displayed in the terminal screen. A workaround is to include sleep 1 clear at the beginning of the script (before any output). This just makes the thing literally wait a second (so that everything that might still get written to the shell has time to get written) and THEN clears the screen. Enjoy, rop PS: - You can of course also give those scripts custom icons (the usual Get Info copy/paste - way. - To really quit Terminal as well, you would effectively need to do some ps -ax and grep/kill stuff, but that may not necessarily be safe because you never know if the user really needs Terminal open. There may be a joint shell script - AppleScript solution, but I don't know it.
__________________ http://www.ropersonline.com Last edited by ropers; February 27th, 2004 at 08:55 PM. |
|
#2
| ||||
| ||||
|
Also, adding the extension .command after making it executable w/ the terminal to a script will make it open with the Terminal.
__________________ MacBook Pro 2.16GHz Core2Duo 3GB RAM, G4 1.4GHz OSX Tiger 1.25GB RAM, Dual 2GHz G5 OSX Tiger 2GB RAM (freakin shweet) Athlon 64 Windoze XP for school work (programming) 1GB RAM dferns@macosx.com |
|
#3
| ||||
| ||||
|
Great one! Moving to howto...
__________________ iMac 24" 2.4 GHz, 4 GB RAM, 320 GB HD. Mac OS X 10.6.2 MacBook Air 13" 1.6 GHz, 2 GB RAM, 80 GB HD. Mac OS X 10.6.2 Mac mini 1.83 GHz, 2 GB RAM, 80 GB HD. Mac OS X 10.6.2 MacBook nano (Lenovo S10e white) 1.6 GHz, 2 GB RAM, 250 GB HD. Mac OS X 10.6.2 iPhone 3GS 32 GB white. Mac user since 1987, Apple Sales Professional 2009, Apple Product Professional 2007-2009, Apple Certified Support Professional 10.5 & 10.6, Apple Certified Pro Aperture 2 (Level 1) |
![]() |
| Bookmarks |
| Thread Tools | |
|
|