image
image

Go Back   macosx.com > Mac Help Forums > HOWTO & FAQs

Reply
 
Thread Tools
  #1  
Old February 27th, 2004, 05:53 PM
Registered User
 
Join Date: Dec 2001
Location: Dublin
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
ropers is on a distinguished road
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 07:55 PM.
Reply With Quote
  #2  
Old February 27th, 2004, 06:08 PM
Captain Code's Avatar
Moderator
 
Join Date: Aug 2001
Location: Ontario, Canada
Posts: 3,107
Thanks: 0
Thanked 0 Times in 0 Posts
Captain Code will become famous soon enough
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
Reply With Quote
  #3  
Old February 27th, 2004, 06:14 PM
fryke's Avatar
Super Moderator
 
Join Date: Sep 2000
Location: macosx.com
Posts: 13,156
Thanks: 2
Thanked 12 Times in 12 Posts
fryke has a spectacular aura aboutfryke has a spectacular aura about
Great one! Moving to howto...
__________________
MacBook Air 13" 1.6 GHz, 2 GB RAM, 80 GB HD. Mac OS X 10.5.5
MacBook 13" 1.83 GHz, 2 GB RAM, 160 GB HD. Mac OS X 10.5.5
Hackintosh Core2Duo 2.4 GHz, 2 GB RAM, 160 GB HD. Mac OS X 10.5.5
iPhone 3G 16 GB (v2.1), AppleTV 1G 40 GB (v2.1)

Mac user since 1987, Apple Product Professional 2007, 2008.
Reply With Quote
Reply

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 07:15 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.