|
|
#1 |
|
Prospect
Join Date: Dec 2002
Location: Phoenix, AZ
Posts: 3
|
Shell script from Finder leaves Terminal window open.
I'm trying to run a shell (perl, actually) script from finder, so I've added .command to the end of the filename, which works beautifully.
The only problem is that the terminal window that gets created to run my .command doesn't obey my defined preference for "When the shell exits: Close only if the shell exited cleanly." The windows stays open with the "[Process Completed]" Message. If I select this window and look up that option, it is set to the default "don't close the window". I'm running 10.2.3, and I have chosen "Use settings as defaults" All new shell windows are killed when bash/tcsh/etc exits... The problem seems to only show up when clicking on .command files from finder. Warning to others: I tried launching the .command file from finder, then tweaking the options (File --> Show Info) while that terminal window was selected, then chose "Use settings as defaults." Don't ever do this. =) The command I was running was stored in my preferences file, and nothing I did would restore it back to a regular shell. The options in the Terminal --> Preferences menu were still pointed at my shell, and no amount of toggling them back and forth made any difference. However, at this point the "Kill this window when shell exits" option /did/ take effect and it was a pain in the ass to get a shell back. So, if this happens to you: Use File --> Run Command and type in your shell... Make sure to click "run in shell" or for some reason it still runs the .command file and kills the window when it exits. Once you have a shell, you can nuke or manually fix up ~/Library/Preferences/com.apple.Terminal.plist This seems to be the only way to get Terminal running a shell again. Anyway... Anyone know how I can get these windows to die when the .command exits? |
|
|
|
|
|
#2 |
|
Guest
Posts: n/a
|
I'm not sure if you want Terminal to quit when the command exits, or just have the window close. If you want Terminal to quit, you could add something like:
/bin/sh kill -3 $(ps wax | grep "[T]erminal.app" | awk '{print $1}') at the end of the script. If you just wanted to close the window, you could maybe do it with Applescript? Something like: osascript -e 'tell application "Terminal"' -e 'close front window' -e 'end tell' You'd have to set "Prompt before closing a window" to never, I guess, and even then, I haven't tried it so it might not work. Sigh. |
|
|
|
#3 |
|
Prospect
Join Date: Dec 2002
Location: Phoenix, AZ
Posts: 3
|
Oddly enough, the "never prompt on exit" option /did/ work for .command files, so I was able to use that applescript. No sweat with having to make that option global, since I was raised on xterm dying when I tell it to. Thanks for the help.
I've been able to narrow this down to a difference between "New Shell" and "New Command"... It's an easier way to test it yourself without renaming stuff and finding it in Finder. Oddly, using "run command inside shell" with New Command doesn't cause the option for automatically closing windows to work as expected, so getting Finder to set that option when launching Terminal would probably be a dead end. Since the option for automatically closing the window when the shell exits seems to be (predictably?) only in effect when a shell is run (not a 'command'), does anyone know how to get Finder to run .command files as if they were custom shells? |
|
|
|
|
|
#4 |
|
Prospect
Join Date: Dec 2002
Location: Phoenix, AZ
Posts: 3
|
If anyone else is interested, I just discovered another workaround that doesn't require the AppleScript to close the window:
Open a new Terminal window running a shell, and make sure it's set to close the window on exit. Save the .term file somewhere and edit it in vi, or whichever text editor works best for you. Change the ExecutionString to the name of the script we're trying to run (say /Users/kgale/bin/foo.pl), but append ";exit" to the end... Example: [...] <key>ExecutionScript</key> <string>/Users/kgale/bin/foo.pl;exit</string> [...] Since you'd be sitting in a shell without that exit command, I assume this is treated as a shell and that's why it obeys the "close window when shell exits" option. This method has the advantage of being able to run unmodified scripts without tagging the AppleScript on them to close the window. The disadvantage is that you have to make .term files for every command you choose to run like this. ...Still looking for the perfect solution... |
|
|
|
|
|
#5 |
|
Guest
Posts: n/a
|
I was gonna mention .term files, but couldn't figure out how to make them double-clickable like a .command file, or how to make them close when they had finished. But of course, they already ARE double-clickable, and putting "command; exit" as the execution string does the trick. I like that better than the AppleScript stuff.
|
|
|
|
#6 |
|
Triple-A Player
Join Date: Oct 2002
Posts: 91
|
That's awesome - I just aasked that same question in another forum. I knew there must have been a better way besides Applescript. One question though, does all this other crap need to be in the file?
<key>AutoFocus</key> <string>YES</string> <key>Autowrap</key> <string>YES</string> <key>Backwrap</key> <string>YES</string> <key>Bell</key> <string>YES</string> <key>BlinkCursor</key> <string>NO</string> <key>CleanCommands</key> <string>rlogin;telnet;ssh;slogin</string> <key>Columns</key> <string>70</string> <key>CursorShape</key> <string>2</string> <key>CustomTitle</key> <string>Terminal</string> <key>DeleteKeySendsBackspace</key> |
|
|
|
![]() |
|
|