How to create an OSX Application to wrap a call to a shell script? My goal is to include in a zip file what amounts to a shortcut, instead of telling my customer(s) to open up Terminal and run a shell script.

My deployable essentially looks like this:

$ unzip Deliverable.zip 
$ cd Deliverable; ls
app.jar run.sh


Script in run.sh:

#!/bin/sh
java -jar app.jar


There's a lot more in the directory; suffice to say I need to run the script from the directory Deliverable since I need to access paths relative to it.  However, I can't guarantee where a customer is going to open Deliverable.zip (could be home directory, could be right in the Downloads directory, etc.)

I found this that describes how to create a new workflow in Automator, then save it as an application to launch a shell script.  I tried to do that to wrap run.sh but it says it can't find run.sh.

Somebody suggested I use applescript and also sent me a link to how to use applescript to switch into the current directory; there's an applescript "action" in automator; so I made a new workflow with that, and saved it as an application.  This is what that looks like:



The code:

on run {input, parameters}
    tell application "Finder"
        set current_path to container of (path to me) as alias
    end tell

    do shell script "java -jar app.jar" 

    return input
end run


And this is the error I get when I run it:



C'mon, this should be pretty simple.  What I am doing wrong here?
I can see a couple of things wrong there.

Firstly you have opened a workflow and not an Application.

You should choose Application when you make your selection for the type of Automator file.



And the code you have will not work as you expect, since you have not changed directory. (cd).

In the code as you have it, all it is doing is getting the path as an alias and storing it in the variable  current_path and in a format unsuitable for the unix commands.

But you do not use it.

So the current directory will most likely be your home folder

At this stage there is no telling what it is trying to launch.

If I run it as you have it I get.



Which makes sense since I do not have Java installed. But if I did I would not expect it to find the right file.

The Applescript need to look like this.

on run {input, parameters}
    tell application "Finder"
        set current_path to container of (path to me) as alias
    end tell

    do shell script "cd " &amp; quoted form of (POSIX path of current_path) &amp; " ;ls | open -fe"

    return input
end run 


In my example

do shell script "cd " &amp; quoted form of (POSIX path of current_path) &amp; " ;/bin/ls | /usr/bin/open -fe"


I cd to the POSIX path of the alias in the  variable  current_path 

i.e from "alias "Macintosh HD:Applications:""   to  "/Applications/"

The quoted form of  escapes the path using quotes.

I have used the /bin/ls command and pipe it to the open in TextEdit stdin as a demonstration here so that you can test to see if you are getting to the area you expect.

You would use something like;

do shell script "cd " &amp; quoted form of (POSIX path of current_path) &amp; " ;\"java -jar app.jar\""




update:

A another way is just use pure Applescript.

on run {input, parameters}
    tell application "Finder"
        set current_path to container of (path to me)

        set theFile to (current_path) as alias

        open file "java -jar app.jar" of theFile
    end tell


end run