Igor R.
Igor R.

Reputation: 429

How to assign values from returned list from AppleScript script to variables in Automator?

In my Automator action, I use an "Run AppleScript" action, that returns a list (via AppleScript). Here is the AppleScript:

on run {input, parameters}
    set result to {"Foo", "Bar", "42"}
    return result
end run

Later in my Automator action, I need to use values "Foo", "Bar", and "42" in different places.

How can I assign those 3 values to different Automator variables?

Upvotes: 2

Views: 1762

Answers (1)

user3439894
user3439894

Reputation: 7555

Taking your question literally, you have to first set the result of the Run AppleScript action, which in this case is a list, to a Set Value of Variable action.

Next, you'd add a Get Value of Variable1 action. setting its Options to [√] Ignore this actions input so as to make a disconnect from the Set Value of Variable action.

Next, add a Run AppleScript action with the following example AppleScript code:

on run {input, parameters}
    return item 1 of input
end run

Then add a Set Value of Variable action for this first item in the list returned from to original Run AppleScript action.

Repeat again for the next two items in the list.

Automator workflow


1Technically you could send the output of the first Set Value of Variable action directly to the second Run AppleScript action to set the first list item to it new variable; however, I broke it into a separate action so the creation of the three list items as separate variables followed the same action path.


Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.

Upvotes: 2

Related Questions