
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." 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.
Categorized:
Mac OS X Help
(Article 3740)
Tagged: Previous: How do you save HTML files with Mac's TextEdit? Next: Wonderful review of "Creating Cool Web Sites" Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. 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 AMI 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 AMOK. 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 AMHmmm... 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 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 PMFound 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 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 AMI 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 PMHopefully someone still checks this because I know its old. 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 AMWOW 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 PMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
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!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|