![]() |
Quitting Terminal after shell script runs
I just wondered if anyone has any tips or thoughts on the best way to make the Terminal quit once a shell script is run?
I could run the shell script in an AppleScript/Automator wrapper, but that's kind of a workaround. I've seen this used: kill -3 $(ps wax | grep "[T]erminal.app" | awk '{print $1}') I realise there's a danger that I might have other processes running when I run my script. |
You could use:
osascript -e "tell application "Terminal" to quit or "do shell script" Applescript command to run it without opening the Terminal in the first place. |
What exactly does the shell script do?
I.e., if there's no user I/O involved, why even run it in a terminal? [i execute many a bash script from Script Menu.] |
Quote:
So bash scripts in the script menu don't run in Terminal...? |
Quote:
|
That's extremely useful. Many thanks for that tip.
|
What exactly is it you are trying to accomplish? Also, if you add the suffix (extension) to a file that ends in ".command" it will make it double click-able to run from the GUI
|
Quote:
Running the script from the scripts menu, or indeed as an AppleScript, would solve the "problem". |
OK, I should have been more clear. How and what are you trying to do exactly, I run scripts on computers all the time with out ever opening up terminal. Is this something you can do remotely?
|
As I said, I have a little script that I double-click on, and it swaps the preference file of an app that keeps corrupting with a clean backup copy. It's literally just a cp command. (Plus #!/bin/sh and exit 0 )
The file is prefswap.sh, it has executable flags set, and when I double-click on it, it opens Terminal. I realise that I could probably achieve the script's result in other ways: but it's more of a general enquiry, as I'm starting to write lots of little scripts. How do you make run your scripts without the Terminal opening, then? |
Quote:
Well, you can set it as a log in hook and have it run at every log in. You can have launchd run it at scheduled times. You can create an alias in your ~/.bash_profile and just execute a single command in terminal and then quit it yourself. You can have the ARD client run it from a task server. If you have any third party enterprise apps available they do it as well. You could even set up a work flow in Automator that would do all of this but I don't really use Automator all that much or ever really. |
Quote:
|
Quote:
|
I could do the alias, but that seems more clicks and keypresses than rather just clicking on the script.
The developer has fixed the problem, but only in the new version, which I'd have to pay the upgrade price for. (They release a new version every year.) It only happens occasionally, so I wouldn't want the script to run every startup. I'm interested in having a whole raft of shell scripts. For instance, I've collated all the "default write" commands that I've used into one script, so that they can be run all at once in a new account or after a reinstall or similar. |
Well one last thing to consider. If this is a user level preference, ie in your home directory, you can modify the user template. So, copy your pristine known good preference into the user template and anytime you delete that plist file, it will grab a new one from the template and it will get a fresh copy of the known good one. If the third party app does this off of their own template you can modify theirs, but as far as I have read (it will need to be tested out) that this method will work. So all you would have to do is just trash that plist in question and when the next new one is made on the fly it will grab it from the template.
|
Nice!
Will give it a go. |
Quote:
That little-known functionality has been around a long time... but it actually broke in an early release of some update (Tiger 10.4.0 iirc), and a few folks around here went bats#!t. [if i can find the thread, i'll add a link.] EDIT: Bingo: "Script Menu and shell scripts" (May 2005) @tlarkin: You seem to be missing the fundamental advantage of being able to have a collection of executables which can be easily run at will by simply selecting them from a menu. Scheduling has its place, but it's not the be-all and end-all of everything. Sometimes we want to run a script on a whim (like benwiggy said), and often it's something related to some other *GUI* task with which we're currently engaged. Being able to drop down the *global* Script Menu (i.e., available from any app), and select a script to run is so much more convenient than shifting over to terminal, and typing out the name of some function (and then shift back to the GUI program). The only remaining thing to be "fixed" here is for you to grasp that point! ;) |
Quote:
Quote:
|
Hal
I know for a fact the user template works with all apple plists, but I have not had the chance to test all third party which is why I gave that disclaimer. I have used it in the past and have verified it works. You can also run scripts from TextWrangler. When I write my scripts TW keeps a quick access menu on the side with every script I have written, and I can highlight and tell it to run or run in terminal or to get output of script. I see the advantage of what you are talking about but was not sure the exact situation of the problem. Which is why I asked, and if it was something that happened on a very frequent basis, why not automate it? Keep it simple, but get all the facts first. |
Quote:
|
I'm not going to argue, but here read for yourself
http://www.macosxhints.com/article.p...11010033851924 http://www.mytechmusings.com/2007/06...-template.html http://www.makemacwork.com/customize...r-template.htm top hits off google, and yes you do need to clear cache when you do this, but it does in fact work. |
I don't need to google. I just deleted my own dock.plist.
The thing is:
>>> and yes you do need to clear cache when you do this, but it does in fact work. If some suggestion doesn't really fit a particular problem (let alone offer any advantage over methods already given), then i don't quite follow the purpose. |
Quote:
Did you actually modify the user template? Just because you don't quite grasp the benefits doesn't make it an invalid option. There are plenty of things you do with your Mac that I have not a clue which you are doing from reading your posts, but I would hardly try to claim them to be irrelevant. The logic behind my suggestion was if you can modify the user template in /System, or perhaps the default template with in the application's contents itself, you can modify the default plist so you never have to run a script. Also, I was unaware of the frequency of this problem, and there have been many solutions which address this in the same manner. I will give an example that Mike Bombich posted on his website. 1) Create a set of plists you want the end user to have 2) Modify the user template and copy over your plists, but make sure to clear caches, logs and other things you don't want every user to have 3) Create a log out script that wipes out all plist files in case the end user modifies anything so next time they log in they get the fresh set of plists from the user template. From the OP: Quote:
You are very smart when it comes to Unix, no doubt smarter than I am, but my methods aren't out of this world when addressing problems like this. I deal with tons of crappily coded educational apps that I have to do things like this from time to time. I try to package it up in composer, with the files modified exactly how I want them to, thus fixing the problem with out having to do any post scripts. |
As far as the 'plist' goes, perhaps it could simply be locked and that might obviate everything.
Quote:
Anyway, this thread had another aspect: "Quitting Terminal after shell script runs"... and, i think one thing readers can take away from all this is the Script Menu tip works for that. If a 'user template' solution ever materializes, i'll be happy to look at it. |
| All times are GMT -5. The time now is 10:37 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.