run bash script from finder

Discussion in 'Apple' started by gchappi, Feb 20, 2008.

  1. gchappi

    gchappi Guest


    I want to run the following script file by doubleclicking from the
    desktop (its an example, in reality I would copy some files around):

    echo "hello (press any key to continue):"

    My problem is, that after executing the file the terminal window stays
    open. Hmm. Is it possible to run such a script without leaving a
    window behind?

    I am coming from Windows and there I would have doubleclicked a *.bat
    file, a window opens and something will be done, finally the window
    closes again.

    The script file has execution rights and will be opened with the (and thus the hash bang sh wouldn't be necessary - I am
    really not sure how this is supposed to be done on Macs).

    I tried to change the Terminal settings to close the shell window, but
    it didn't help. The only solution I found, was to kill the terminal
    (#killall Terminal) but I rather don't want to do it because it would
    also kill any unrelated terminal windows.

    Hopefully someone can help. I really don't know how this is supposed
    to work.

    gchappi, Feb 20, 2008
    1. Advertisements

  2. gchappi

    gchappi Guest

    Why open the window *at all*? Why not just wrap the shell commands in an
    * I don't know AppleScript and it would (probably??) be less standard
    then a bash script
    * It is rather lowlevel: add permission files from an usb stick to an
    ** mount
    ** ssh-add <filename> ...

    gchappi, Feb 20, 2008
    1. Advertisements

  3. gchappi

    gchappi Guest

    And that's why we are here - to help you learn. ; )

    you did ...!
    works fine and I can easily call my own script (do shell script "~/

    I will probably go this way and have to find out some more things
    like, e.g.
    - do shell script "~/Desktop/start sshAgent" (with empty spaces)
    didn't work
    - get exit codes from my script and display error messages if

    Thanks again,
    gchappi, Feb 20, 2008
  4. gchappi

    BakersT Guest

    Another alternative is to use 'Platypus' to create a Mac application
    (double-clickable, drag-n-drop, etc) from your script:


    It's a great tool, and freeware!
    BakersT, Feb 20, 2008
  5. gchappi

    Daniel Cohen Guest

    If you don't like Jolly Roger's suggestion elsewhere, you can do the

    Add a line at the end of your shell script that reads

    osascript -e 'quit application "Terminal" saving no'

    osascript calls AppleScript, -e is a flag that says that the bit between
    ' and ' is the required script, whose meaning is obvious.

    I had to do that in a situation where only a shell script could be used,
    not an ordinary AppleScript.

    If you need a script of more than one line, either use -e for each line,
    or save the script and just use

    osascript FullPathToScript
    Daniel Cohen, Feb 20, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.