Show Results of Automator-Terminal command
TL;DR If I create a .app via Automator, how can I show results of a shell script in a dialog or terminal window?
I am using Automator to run a shell script
adb install /Directory/$1.apk
and if I run it via Automator, I can see the results (install successful or can't find filname.apk or whatever else terminal would tell me). If I save as app and double click to run, then I do not get to see these results.
What can I do to show a dialog or terminal window that would display the results of the script I run?
There are a couple of ways you could do this:
- Adding an Ask for Confirmation action after the Run Shell Script one and using
$1
in the message field. - Adding another Run Shell Script and executing
osascript -e 'tell app "System Events" to display dialog "$1"'
. You'll have to select as argument on the pass input drop down.
If you only have a few lines of output, you'd want to assign it to a variable and then display a confirmation dialog showing the output.
- add Action "Set Value of Variable"
- enter a new variable, e.g.
output
- add Action "Ask for Confirmation"
- in the message field, enter the variable name declared above. While typing the variable name, Automator will suggest to complete the variable name. Accept by pressing Enter key. This prevents Automator from interpreting the variable name as a plain text message.
This will look like this:
NB: I also tried the $1
approach, but did not succeed.
If you have a lot of lines of output, you should direct all output into a new TextEdit document. To do so, just add the "New TextEdit Document" Action after your script action.
This may look like this:
Hint: diagnostic messages are often output to standard error. To also collect text send to standard error, add exec 2>&1
at the top of your bash script.
Need to use "Set Value of Variable"