简体   繁体   中英

How to use Variables in Automator

please bear with me, I use Automator since not long.

I have good experience in PHP (totally different) and some small scripting knowledge (apple script, shell, etc).

I try to replicate this logic workflow with Automator:

  1. Ask User to insert value (set $variable_a)
  2. Ask User to insert one more value (set $variable_b)
  3. Submit
  4. This triggers a script that uses both values submitted above. A dummy example:

    echo $variable_a echo variable_b

Seems simple, and it's amazing how fast you can set up this logic with Automator.

The problem is, at stage 2 above, my $variable_a is suddenly a mixed value of $variable_a and $variable_b .

Why does this happen?

They do not seem to act as I understand the generic usage of "variables" in any language or programming step. In other systems, usually, variables keep as value what they got defined (unless variable variables or you modify them consciously in the code)

I attached an Automator "WorkFlow" File that replicates exactly the abovementioned WorkFlow Logic. It's a ZIP file, unzip it and open in Automator for a test.

You will see (in the results section for the last step) how the values become (IMHO) false.

Has someone a hint?

The reason this is happening is because the output of one action in the workflow is being fed as input into the next action of the workflow. As inputs are received by actions, they can also aggregate in some cases, such as when setting and getting variables.

The reason it does this is so that you could sent multiple variables directly into, say, a Run Shell Script action, and references them using $1 , $2 , etc. If Automator only ever took the most recent input, you'd never be able to feed more than one variable into a shell script without first combining them manually yourself into a list.

The solution is simple. Every action has an Options button that you can press, which in turn reveals a checkbox called Ignore this action's input . This needs to be checked for those actions that you want to operate independently of previous results.

Here's a screenshot of your workflow with the appropriate checkboxes ticked against the actions that require it:

Automator工作流程

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM