7

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?

2

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.
  • 4
    It just displays $1 with either of those methods. – Reed Jan 11 '14 at 19:21
  • @Jakar I've tested it having the first Run Shell Script action doing echo something and it definitely works. Perhaps you're Script is not returning something? – Thecafremo Jan 11 '14 at 23:30
  • Okay. I'm thinking it may have something to do with adb (part of Android developer SDK), because there is output in Terminal after I run that command, but not via the automator script. – Reed Jan 12 '14 at 3:37
  • Slight modification to handle the string interpolation osascript -e 'tell app "System Events" to display dialog "'"$1"'"' – bingles Oct 28 '15 at 14:52
15

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.

  1. add Action "Set Value of Variable"
  2. enter a new variable, e.g. output
  3. add Action "Ask for Confirmation"
  4. 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: Automator with text output

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: New Text Edit document action

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.

  • 1
    wow exactly what I needed ! – code4j Jan 10 '16 at 13:05
  • 1
    this solution worked for me whereas the accepted version did not – Ilias Karim Jan 30 '16 at 10:13
  • this was really useful to me and explained why I couldn't get the value of the output. great job – CommentLuv Feb 27 '17 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .