Execute a .sh script by "double-click"

Discussion in 'Mac Programming' started by darrengreer, Jul 2, 2006.

  1. macrumors regular

    Joined:
    Jun 11, 2006
    #1
    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?
     
  2. macrumors 6502a

    solaris

    Joined:
    Apr 19, 2004
    Location:
    Oslo, Norway
    #2
    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
     
  3. thread starter macrumors regular

    Joined:
    Jun 11, 2006
    #3
    The .command rename worked beautiful. Thanks
     
  4. macrumors newbie

    Joined:
    Jun 9, 2010
    #4
    .command errors?

    Whenever i rename my .sh into a .command, it says i don't have rights. I know i do.
     
  5. macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #5
    In terminal.app

    Code:
    sudo mv /location/of/file/script.sh /location/of/file/script.command
    
     
  6. macrumors newbie

    Joined:
    Jun 9, 2010
    #6
    This doesn't work for me. It still gives me that i don't have the right permissions.
     
  7. macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #7
    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
    
     
  8. macrumors newbie

    Joined:
    Jun 9, 2010
    #8
    nevermind, i am just running it as an app through applescript
     
  9. macrumors newbie

    Joined:
    Jan 7, 2011
    #9
    running .sh script by double-clicking on it

    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
     
  10. macrumors 6502

    Joined:
    Aug 19, 2010
    Location:
    UK
    #10
    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!
     
  11. zarl1n0, Feb 1, 2011
    Last edited: Feb 1, 2011

    macrumors newbie

    zarl1n0

    Joined:
    Feb 10, 2010
    #11
    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.
     
  12. macrumors 68040

    Joined:
    Feb 2, 2008
    #12
    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
     

Share This Page