Assign action to variable in Automator for use in Shell Script Assign action to variable in Automator for use in Shell Script shell shell

Assign action to variable in Automator for use in Shell Script


The Automator variables are only used in the Automator workflow. The variable themselves are not directly accessible to either a shell script or a Python script. The Run Shell Script action allows you to pass the values of particular variables to a shell script in either of two ways: either piping them in through stdin or by passing them as execution arguments. For this sort of use case, the latter is easier. To start with, you need to pick Automator variable names in the Set Value of Variable and Get Value of Variable actions so the values selected can be retained between actions. Here's a very rudimentary workflow example where I've selected two folders:

enter image description here enter image description here


You might use a Run AppleScript action like this to display the dialogs:

POSIX path of (choose folder default location (path to desktop))result & linefeed & POSIX path of (choose file default location (path to desktop))

Then set "Pass input" to "to stdin" in the Run Shell Script action and use a script like this:

import sysfolder, file = sys.stdin.read().splitlines()