run bash script from finder

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

  1. gchappi

    gchappi Guest

    Hello,

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

    -----
    #!/bin/sh
    echo "hello (press any key to continue):"
    read
    exit
    -----

    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
    Terminal.app (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.

    Thanks,
    Hans-Peter
     
    gchappi, Feb 20, 2008
    #1
    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
    ssh-agent
    ** mount
    ** ssh-add <filename> ...

    Thanks,
    Hans-Peter
     
    gchappi, Feb 20, 2008
    #2
    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 "~/
    Desktop/startSshAgent").

    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
    necessary.

    Thanks again,
    Hans-Peter
     
    gchappi, Feb 20, 2008
    #3
  4. gchappi

    BakersT Guest

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

    <http://www.sveinbjorn.org/platypus>

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

    Daniel Cohen Guest

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

    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
    #5
    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.