4

I have made a small automator script that runs a bash shell script and gets two outputs... On viewing results it appears like this below...

Multiple Results

I want them in two automator variables Assume I used a script like

echo "200"
echo "19 hours, 4 minutes and 42.765 seconds"

and on viewing the results it shows this (and I want each of these as automator variables called count and duration). I want it to be sent to a display notification with subtitle as "count files processed" and message as "duration elapsed". How can I achieve this?

Saifur Rahman Mohsin
  • 929
  • 1
  • 11
  • 37
  • I've barely used Automator, and this may or may not be useful, but it came up on google: http://moonsharke.wordpress.com/2011/06/03/multiple-variables-for-automators-run-applescript-action/ – Jordan Running Aug 29 '14 at 21:49
  • Thanks a lot but that doesn't seem to help much. The link you provided shows how to take the output into AppleScript as an array and then later extract variables from that array; all done in applescript rather than automator. I am trying to get both lines into separate automator variables – Saifur Rahman Mohsin Aug 29 '14 at 22:12
  • Maybe this will help: http://www.peachpit.com/podcasts/episode.aspx?e=8c60f1b7-cf99-42fa-9fca-0ac36dff2f07 – webb Aug 30 '14 at 04:49

1 Answers1

4

You can modify Automator variables by applescript. The variables must exists in the workflow, so you first should add two variables, to get something like on the next image:

enter image description here

You can set anyting as their initial value...

After the above, you can use the next applescript, right after your shell script

on run {input, parameters}
    set value of variable "Count" of front workflow to item 1 of input
    set value of variable "Duration" of front workflow to item 2 of input
    return input
end run

It is not fully correct, (for example it isn't check the number of arguments on the input), but you get an idea.

So after the next:

enter image description here

Your automator variable Count will contain 200, and the variable Duration will contain the text.

clt60
  • 62,119
  • 17
  • 107
  • 194
  • Annoyingly, this doesn't seem to work in reverse. Ie, you can't do "get value of variable 'Count' of front workflow"; it won't error but will always return an empty string. – Wowfunhappy Jul 23 '18 at 14:58
  • Boo Apple! Although this works inside of Automator, it won't work at all once you save the workflow out and run it as a service, because there's no longer a "front workflow" window. I wasted an hour figuring this out. As far as I can tell, the only solution is to restructure your workflow (repeating the Applescript) so that only one variable gets set per Applescript block. – Wowfunhappy Jul 23 '18 at 18:24
  • (or repeating the bash script block, or whatever action is actually generating variables) – Wowfunhappy Jul 23 '18 at 18:51