QuickTopic free message boards logo
Skip to Messages



12:50 AM ET (US)
Wow, lovely portal. Thnx ...

Feel free to visit my webpage - world Class university
03:30 PM ET (US)
You're a really helpful internet site
Edited 03-15-2021 03:30 PM
07:12 PM ET (US)
the answer you need seems to depend on how you work, so:

if you run the script from a Terminal window, and want it closed as soon as your script executes, just can get the process id of the PARENT process (which will be the shell == your Terminal window) and kill that. essentially, you are writing a suicidal script, or technically, a patricidal script. (if you're the type of person who thinks about such things.)

the way to do the above is just to add:
kill -9 $PPID
to the end of your script.

(make sure your terminal prefs are set to close the window when the shell exits, or your stale window will hang around.)

on the other hand, if you mean to launch those apps on login, then just run your script from your .login/.profile/.bashrc/whatever init file corresponds with the shell you're using (most likely bash). then they'll stay open until you close them. (prolly not what you want, but who knows?)

finally, if you are using this script as a generic gui app-launcher, then it sounds like ssp's advice of using applescript is the way to go -- not because applescript is particularly capable, but because it's stitched to tightly to the gui. i swore off applescript in my university days, and so i can't speak to what its present day os-x capabilities are, but it would be a poor applescript indeed that couldn't fire off your shell script, giving you the power of the nix shell and the nice interface of aqua -- and isn't that what os/x is really all about?
Sam Griffith Jr.
03:41 PM ET (US)
In your Terminal application, if you go to the application menu, then to the Window Settings... subMenu, you can set what you want the shell to do when it executes a script. Close Window, Don't Close Window, or Close only if shell exited cleanly.

This should do the trick...

Sam Griffith Jr.
08:53 AM ET (US)
Honestly I can't see any good reason for not doing this in AppleScript entirely. Launching ScriptEditor and typing a couple of tell app "abc" to run commands doesn't look harder than using the Terminal and pico - it's even easier and will give you a perfectly double-clickable application.

Also doing it this way avoids using the application's path, which is a good thing.

Even if you really need to do some command line stuff that cannot be trivially achieved in AppleScript, you can still execute it from an AppleScript without any hassle and don't need to worry about using the Terminal, it being double-clickable and all.
04:41 PM ET (US)
You can use applescript from a shell script with osascript. I didn't test this code, but something like it should work (and it will only close one window, other Terminal windows will stay open):

osascript <<-ENDSCRIPT
tell app "Terminal"
  close every window whose processes contains "nameOfScript"
end tell
MrHappyPerson was signed in when posted
03:15 PM ET (US)
tate: worked like a charm. Thanks!
03:06 PM ET (US)
If you don't mind shutting down the terminal app altoghter, i.e., all other windows as well as the one you're executing the script from, etc., add the line:

killall Terminal

that should work if you're running Jaguar.
Edited 11-04-2002 03:23 PM
MrHappyPerson was signed in when posted
02:17 PM ET (US)
Stef: AS would certainly do the trick but like I said to dsandler, going this route is about as simple as it gets: pico and a text file.
MrHappyPerson was signed in when posted
02:16 PM ET (US)
George: dbl-clicking on it fires up Terminal and opens a window. I don't think it can not do that, at least the way I've written it. That's with the executable bit set.

dsandler: thanks, I'll check those other options out. What I really liked about this script is that I can edit it in pico from the terminal, and not need any other applications. Its about as simple as it gets.

How about being able to quit Terminal from the script? That'd do the trick.
dsandlerPerson was signed in when posted
01:47 PM ET (US)
Chris: I don't think there's a way to get the Terminal to reliably close the window. (At least, I haven't found a way.) Instead, you might want to wrap up your script with a Cocoa frontend, avoiding Terminal.app altogether; there are a few options available (I found DropScript to be straightforward; the same group at U. Michigan that makes Fugu also makes something called iHook which is a really sophisticated shell script wrapper).

ggirton: To make a shell script executable, you need to set the executable bit on the file. From a Terminal, you'll want to do the following:
chmod +x my-shell-script
Edited 11-04-2002 01:48 PM
11:58 AM ET (US)
Why not just use AppleScript instead?
George Girton
11:45 AM ET (US)
When you run your script, can you run it NOT from within a terminalwindown but by just clicking on it? Maybe that would work -- it wouldn't open up the terminal window to begin with.

By the way, I clicked on this link from Meerkat to see if I could learn how to create a shell script that runsfrom terminal to begin with. I make the file, but how do you make it executable so it can run?

ggirton @ mac dot com

Print | RSS Views: 1958 (Unique: 1227 ) / Subscribers: 0 | What's this?