# Invoking a shell script graphically?



## TommyWillB (Apr 1, 2001)

Is there a way I can invoke a shell script by double-clicking a desktop icon?

Certainly I can do a lot with AppleScript, but it is not clear to me if AppleScript can invoke a shell script.

On WinDoze you can do a certain amount of this by coding your command into a shortcut. I can't figure out if there is a way to do this via an Alais.

Is there a way to associate all .sh files so that when double-clicked they launch the terminal and run there? (Not really what I want, but may be okay.)


Even better I'd like this script to run as a particular user... not just the user of the person who clicks it.

Any ideas?


----------



## endian (Apr 1, 2001)

you want DropScript:

ftp://isp.mit.edu/users/tritan/MacOSX/DropScript-0.2.dmg.gz


----------



## TommyWillB (Apr 1, 2001)

It has no instructions...

What do I do with it?


----------



## endian (Apr 1, 2001)

from Fred Sanchez's post to the OSX-dev list: (he wrote the app)

  The demo I wrote is a small application called DropScript.  You drop any executable program (for example, a shell script, a perl script, a C program, ...) onto the DropScript app icon (or launch DropScript and use the open panel), and DropScript will create a new application using your program.  The new application, in turn, can be used in Finder to run your program on files.  For example, you can write this shell script:

	#!/bin/sh
	gzip -9 -- "$@"

  Save it as GZip.sh.  Drop this on DropScript, and you get a new program (in the same location as the script) called DropGZip.sh.  Drop any file onto DropGZip, and it will compress the file using GZip for you.  You could also get similar results (sans the -9 option; and the '--' keeps it from complaining about files that begin with '-') by simply dropping the gzip executable itself onto DropScript.  But shell scripts a smaller and far more flexible than binaries.


----------



## vihung (Apr 9, 2001)

You can write a shell script - give it a .command extension and make sure it is executable (chmod +x ...)

You can then double click on it in the finder and it will do whatever you tell it to do.


----------



## ttimes (Apr 12, 2001)

Also, associating the application Terminal with the script 'document' in question works fine.

Cheers!


----------



## rharder (Apr 12, 2001)

Okay, vihung, you win the tip-o-the-day prize for that .command thing. That's a life saver.

-Rob


----------



## dani++ (Apr 12, 2001)

Cool.


Nevertheless, don't put any spaces in the command's filename or path, otherwise the invocation from terminal will fail. One hidden 'feature'... =)


On the other hand, I've successfully invoked the command, which only does an 'open'... the script is executed, but somehow the opened app doesn't show up (it might be killed at the end of the script or something). Any pointers?


dani++


----------



## rharder (Apr 12, 2001)

You sure wouldn't think the opened app would die right away, but you could try a nohup:


```
nohup open MyApp &
```

(Interesting. The above formatting is what you get when you use the vB 
	
	



```
tags.)

-Rob
```


----------



## dani++ (Apr 13, 2001)

Definitely doesn't work, even using 'nohup'.

If I invoke the file from the terminal it works great, but if I double click on it the 'open' command doesn't work.


Thanks for the suggestion anyway.

I'll post here if I achieve some success.


Dani


----------



## theed (Apr 15, 2001)

There's a property to the left of the other properties if you look at the permissions on the command line. the sticky bit or whatever.  Anyway, if you do a mn on chmod you'll find Set UID on execution.  If you apply chmod u+s (or something like that) and the owner of the file is root, then the file should be executed as root.  

I've done this on X Server, and it works, but be careful, and I don't know how much of this is still applicable on X.  I'd assume all of it.


----------



## sfish (Apr 15, 2001)

With my addition, this string officially belongs in the Unix Newbie forum.     I'll try to keep it short. I've created a shell script app with DropScript containing a simple command <b><blockquote>ssh username@servername</blockquote></b>It didn't work. I tried adding <b><blockquote>#!/bin/sh</blockquote></b>to the beginning and it still didn't work.

Changing the extension to .command and making the app executable (chmod +x {appname}) made it so double-clicking the app launched Terminal, but nothing else happens.

Of the extensive list of things that I could be doing wrong, I would be most appreciative if someone would do two things:

1) Help me understand what I did wrong.

2) Help me get this script working.


----------



## theed (Apr 15, 2001)

I find that in scripting, you shouldn't count on paths resolving, so ssh should maybe be
/usr/local/sbin/ssh bob@turbopron.com


----------



## sfish (Apr 15, 2001)

Well I did a <blockquote><b>which ssh</b></blockquote> just to make sure I was putting in the correct path.  It didn't help.

Thanks for the input anyway!

Anyone else?


----------



## rharder (Apr 16, 2001)

Well, you'd think it would work the way you had it, but I tried it this way:
	
	



```
#!/usr/bin/ssh rob@localhost
```
 in a ssh.command file. It executed from the Finder, but the .command thing isn't expecting input, apparently. I got a "You have no controlling tty. Cannot read passphrase" error.

Is your goal to make some sort of shortcut to launching a ssh session easily?

-Rob


----------



## sfish (Apr 16, 2001)

Yes.  And to figure out why this won't work.


----------

