Return value from an app?


#1

Hi,

Is this possible to get the return value from a Foo.app launched with a bash script? For instance below i always get the 0 value (while i use “setApplicationReturnValue” in my code).

open -W Foo.app --args bar
echo "$?"

My assumption is that it is not possible without calling directly the binary (e.g. Foo.app/Contents/MacOS/Foo). Is there any obvious trick that i’m not aware?


#2

Thus, finally i communicate by writing and reading a text file.


#3

I think that this is not supposed to work  at all with the open command:

if you do echo "$?", this will actually print the return value of the open command (where 0 probably means "opened successfully"), and not the return value of the app itself.


#4

Yep, you are right. I realized it later, searching in StackOverflow archives.

(For future readers), consequently i use a log file.

# Read the result in the log file.

result=$(tail -n 1 "$log")

if [ "${result:0:9}" = "Succeeded" ]; then
    echo "### PASS"; exit 0
fi

# Open the log file in case of failure.

open "$log"
echo "### FAIL"; exit 1