View Full Version : Running a Shell Script via a Desktop Shortcut
04-13-2007, 03:16 PM
I'm using OSX 10.4, and I've created a simple shell script that I'd like for the user to be able to be able to run be clicking a shortcut on the desktop instead of having to open Terminal and execute the script from there.
Currently, when I click the shortcut, the file just opens in TextEdit, as that is the application associated with ".sh" files on the system. I thought that maybe I needed to associated ".sh" files with Terminal, but it is greyed out when I try to choose a new application to associated with ".sh" files.
Can anyone tell me what I need to do?
04-13-2007, 05:32 PM
Open Script Editor
create Applescript using this strategy:
do shell script "mv ~/Desktop/whatever.doc ~/Documents/whatever.doc"
(replacing, of course, with the shell script you actually want to run)
Save as AS application, put on Desktop.
04-13-2007, 06:20 PM
I'm pretty sure that if you give the file an extension of ".command" (and make sure it's executable), it will then execute when you double-click the file.
When I make a text file whose contents are:
and give it the name ls.command, I can double-click it and it will list the contents of my /Users directory in a Terminal window.
04-13-2007, 10:40 PM
Script Menu (http://www.apple.com/applescript/scriptmenu/)
It's not a "desktop" shortcut... but, it's probably better.
04-19-2007, 12:36 PM
Question ab out this.
I have made commands using the .command technique and the apple script -> do shell script.
How can you get the terminal window to close after the command has completed?
I write all of these scripts but the terminal windows just stay open... even with an exit command at the end of the script.
04-19-2007, 05:27 PM
I have made commands using the .command technique and the apple script -> do shell script. How can you get the terminal window to close after the command has completed? I write all of these scripts but the terminal windows just stay open... even with an exit command at the end of the script.
What does your script "do"?
I.e., do you even need a terminal window at all?
If not, then the .command name isn't necessary,
and possibly the 'apple script -> do shell script'
isn't either. Read up on Script Menu (link above).
Anyway, without knowing the purpose of your script,
and/or seeng the actual code... it's anybody's guess.
04-19-2007, 05:48 PM
I launch certain applications from the terminal to enforce the bash shell exports.
That way I can force my environment on the application when it runs. Like shake for instance.
I want the terminal running while the app is running because you can read errors there much easier than within the shake console. But when the application ends I would like the terminal to close.
so the script is just
I made it as a .command file so I can place it in the doc so it is easer for my users.
and like I said, I force my environment on them on every launch of the application so that I can change the whole facility on the fly because they source a master environment script.
But I would like the terminal to close when the app closes. Don't get me wrong... I also like having it stay open.. because it also helps me diag. issues. but most times I would like it to close, and if I need to diag something I will just run shake from the command line.
I know this is an ancient thread, but to those that might still be looking for a way to automatically close the terminal window when the shell script ends, do this...
Terminal -> Preferences
Highlight the default layout from the list on the left
Under "When the shell exits" select either "Close if the shell exited cleanly" (my preference)
or select "Close the window"
You also want to make sure that "Prompt before closing" is not set to "always"
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.