Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

Binding Terminal to a shell script

Here's an interesting question I received from a reader:
"In Mac OS X, have you ever done "Get Info" on a shell script, made it open with Terminal, and had it forcibly execute every time you open the Terminal app and then exit? Any idea how to fix this? I've changed the path to the script and now it complains that the script is not there but still forceably exits after failing to execute the original script."

Dave's Answer: If you think about this from a Mac OS X "Aqua" perspective, it makes some sense.

If you tell the OS to associate the shell script file with the Terminal, every time you click on the script icon, it'll be executed in the Terminal application. Just like a PDF bound to Preview, or a JPEG associated with GraphicConverter.

The only reason that I can imagine that a script would be executed when you open the Terminal application has nothing to do with the "Get Info" application binding, and everything to do with what's in your .login or .bashrc file.

Check those and see if you invoke the script from within one of those. I bet you do, somehow...

In any case, good luck. This is certainly an interesting puzzle!

Please report back.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

I'm the reader in question. I come from a Unix background, so the first thing I did was check my .bashrc, .bash_profile, and such.

I also grepped for the name of the script that's being called with a full recrusive search starting at / with no matches. That's why I'm so puzzled.

If I log in as a different user, then su -u as the user with the problem, the problem doesn't appear, even if I explicitly call bash again. That's why I'm pretty confident that the problem is at the Aqua level rather than the command-line Unix level.

Posted by: Kevin Baird at September 18, 2004 6:31 AM

I have to say that I'm stumped. If you open up an application like Preview, does it also open up any of the PDFs on your system? I doubt it, so I just can't imagine how your script got associated with the launch of Terminal. What happens if you type "open -a Terminal" from within a Terminal window?

Posted by: Dave Taylor at September 18, 2004 7:03 AM

OK. I upgraded from Jaguar to Panther, as already planned before the Terminal trouble. No change - no surprise there.

I then logged in through Aqua as a different user. Then did 'su' to become the user with the problem. Then a 'cd' to make sure I'm in my home directory. 'open -a Terminal' shows nothing on screen, but has a slight delay -- about as long as it takes to run my associated script and exit, as happens when logged in directly as the poor victim account.

The Aqua user has tcsh as a default shell. Executing 'bash' has no problem. Executing 'open -a Terminal' from within bash has the same behavior as within tcsh.

Thanks also for such a quick reply, Dave.

Posted by: Kevin Baird at September 21, 2004 9:33 AM

Hmmm... so it's something to do with the tcsh configuration, then. Here's what the man page says about tcsh startup on Mac OS X:

A login shell begins by executing commands from the system files
/etc/csh.cshrc and /etc/csh.login. It then executes commands from
files in the user's home directory: first ~/.tcshrc (+) or, if
~/.tcshrc is not found, ~/.cshrc, then ~/.history (or the value of the
histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the
value of the dirsfile shell variable) (+). The shell may read
/etc/csh.login before instead of after /etc/csh.cshrc, and ~/.login
before instead of after ~/.tcshrc or ~/.cshrc and ~/.history, if so
compiled; see the version shell variable. (+)

In addition, I have a niggling memory of an environment variable that can point to a startup script, but can't seem to find anything about it in the man page...

Posted by: Dave Taylor at September 21, 2004 5:13 PM

Found it! details to follow:

Well, the problem persisted even after checking of those files and changing the shell to bash (which I prefer anyway).

However, I made a backup directory outside of my ~, and moved everything in ~ to that (hidden files not included). Now, when I call up a Terminal window, I get default settings, including that awful black text on white background.

I guessed that if I had only moved my Library folder, something inside there woudl have done. Behold: ~/Library/Preferences/com.apple.Terminal.plist is an XML file with Terminal config settings. Here's an excerpt:

ExecutionString
[name of the shell script]

So it was an Aqua app preferences file, rather than the regular BSD-derived .*sh* files we were looking at.

Thanks for all your help with this question, Dave. You suggested several things I would not have thought of. Good luck with any future books.

Posted by: Kevin Baird at September 22, 2004 9:00 AM

I know this is old, but I have to say thanks Kevin for figuring this out, and thanks Dave for hosting this tip! I believe the problem arises when you use the mysterious "Use Settings As Default" button under "Terminal > Window Preferences." If you started the app by double clicking a script and use that button, it appears to set that plist option.

Working stupendously now; thanks again!

Posted by: Josh at September 3, 2006 8:46 PM

Hopefully someone still checks this because I know its old.
I'm having this same problem but I don't know how to fix it. I just began using Xcode and executed a script and clicked the "Use Settings As Default" button. I just would like to know exactly what to do to fix the problem.
I'm a newby so please help.

Posted by: Bryant at March 2, 2007 12:10 AM

Edit the file ~/Library/Preferences/com.apple.Terminal.plist

If it is in binary format (new in 10.4), use plutil to convert it to XML.

Remove the value of ExecutionString.

Posted by: Jacob Tjoernholm at September 21, 2007 5:33 AM

WOW THANKS SO MUCH!!

I had the same problem, and spent forever trying to solve it. I had to stop the script from ecuting in the ~/Library/Preferences/com.apple.Terminal.plist

Posted by: tom at October 28, 2007 11:11 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]