Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

darrengreer

macrumors regular
Original poster
Jun 11, 2006
142
0
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?
 
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
 
solaris said:
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
 
.command errors?

Whenever i rename my .sh into a .command, it says i don't have rights. I know i do.
 
This doesn't work for me. It still gives me that i don't have the right permissions.

try going

Code:
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:

Code:
sudo su - 
chown yourusername /location/of/file/script.sh
exit
mv /location/of/file/script.sh /location/of/file/script.command
 
running .sh script by double-clicking on it

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
 
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!
 
Use cat and chmod

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.

Code:
cat file.sh > file
chmod +x file

Make sure to leave off the extension of the new file name.
 
Last edited:
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.