PDA

View Full Version : Running a Shell Script via a Desktop Shortcut


Burritonator
04-13-2007, 02:16 PM
Hi,

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?

Thanks

AHunter3
04-13-2007, 04: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.

retcynnm
04-13-2007, 05: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:

ls /Users

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.

Hal Itosis
04-13-2007, 09:40 PM
Script Menu (http://www.apple.com/applescript/scriptmenu/)

It's not a "desktop" shortcut... but, it's probably better.

-HI-

gotTheShakes
04-19-2007, 11:36 AM
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.

Any thoughts?

Hal Itosis
04-19-2007, 04: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.

-HI-

gotTheShakes
04-19-2007, 04: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

#!/bin/bash
shake -vv
exit


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.

sjf
06-10-2012, 10:08 AM
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
->Settings tab
Highlight the default layout from the list on the left
->Shell tab
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"