PDA

View Full Version : Execute a .sh script by "double-click"




darrengreer
Jul 2, 2006, 03:50 PM
I know I figured this out once before, but can't seem to find an answer in my searching of this forum and google.

So, I have a .sh script, which is world executable. If I want to run it by double-click, what do I need to do?



solaris
Jul 2, 2006, 04:13 PM
I guess you have two options:
* Rename the shellscript from .sh to .command, then associate it with Terminal.app
* Use 'Platypus' to create a .app from the shellscript

darrengreer
Jul 2, 2006, 04:42 PM
I guess you have two options:
* Rename the shellscript from .sh to .command, then associate it with Terminal.app
* Use 'Platypus' to create a .app from the shellscript

The .command rename worked beautiful. Thanks

gggccc
Jul 2, 2010, 10:10 PM
Whenever i rename my .sh into a .command, it says i don't have rights. I know i do.

MorphingDragon
Jul 3, 2010, 06:01 AM
Whenever i rename my .sh into a .command, it says i don't have rights. I know i do.

In terminal.app


sudo mv /location/of/file/script.sh /location/of/file/script.command

gggccc
Jul 3, 2010, 08:26 AM
In terminal.app


sudo mv /location/of/file/script.sh /location/of/file/script.command


This doesn't work for me. It still gives me that i don't have the right permissions.

MorphingDragon
Jul 3, 2010, 08:52 AM
This doesn't work for me. It still gives me that i don't have the right permissions.

try going


sudo su -
mv /location/of/file/script.sh /location/of/file/script.command


Root has access to everything.

If for some fantastically stupid reason that still doesn't work try this:


sudo su -
chown yourusername /location/of/file/script.sh
exit
mv /location/of/file/script.sh /location/of/file/script.command

gggccc
Jul 3, 2010, 10:20 AM
nevermind, i am just running it as an app through applescript

uroscadez
Jan 7, 2011, 09:46 AM
This doesn't work for me. It still gives me that i don't have the right permissions.

Here's how you fix this... It is actually not the permissions ...the file needs to be set as "executable". In Terminal write:

chmod 777 filename.command

that works...tested ! ....very old Unix trick

Example:

type "chmod 777 filename.command"
then type "ls -la filename.command"

the result should look something like this:
-rwxrwxrwx@ 1 uros admin 162 Jan 7 16:27 filename.command


Uros Cadez

Tonsko
Jan 7, 2011, 09:50 AM
After a lot of fiddling, I turned a shell command into an applescript, and then 'built' it as an app, and gave it an icon. Now I have a nice 'lock terminal' command with a shiny padlock icon in the dock. It's not totally 'clean' as when you unlock it you have a terminal window hanging around on the desktop. (#firstworldproblems :D)

Why do I need this? Because I use it for testing in a datacentre, and leaving it running network/application tests safely while I go off and do something else is valuable!

zarl1n0
Feb 1, 2011, 09:05 PM
You can make a file executable on double-click by using cat and chmod. Use cat to strip away the type code of the file---which tells which kind of file it is---and then use chmod to make it executable.


cat file.sh > file
chmod +x file


Make sure to leave off the extension of the new file name.

subsonix
Feb 1, 2011, 09:16 PM
You aren't striping away the header you are creating an identical file with a new name. The header of a shell script is something like this: #!/usr/bin/bash