How to pass two variables from previous actions to “run applescript” in Automator

applescriptautomator

What I'm trying to is:

  1. Receive a string from "Ask for Text".
  2. Get a file from Finder.
  3. Do some codings these inputs in Applescript.

Seems like Applescript only receives file as input, I have no idea how to pass string from step 1 to it. Any suggestions are appreciated.

note: all "ignore action's input" are uncheck.

The workflow looks like this:
enter image description here

Best Answer

For my normal usage, typically when using a Set Value of Variable action, the subsequent action will have the [√] Ignore this action's input checkbox checked. This is because one does not typically set a variable and then pass it directly to the next action, unless of course the value of that variable will also be needed elsewhere in the workflow and the next action also makes use of the variable. Since a Ask for Finder Items action in your use case as shown in your question isn't going to use the variable, I've checked the [√] Ignore this action's input checkbox checked, in the Ask for Finder Items action. Of course adjust to your needs.

Now to pass both what's returned by the Ask for Finder Items action and the value of the Variable_1 variable, place a Get Value of Variable action between the Ask for Finder Items action and the Run AppleScript action.

Then in this case, input in on run {input, parameters} is a list of two items, the first being what was passed from the Ask for Finder Items action and the second being the value of the Variable_1 variable from the Get Value of Variable action, and here's an example AppleScript code addressing what is shown in your Run AppleScript action to handle it:

on run {input, parameters}

    set filePath to the POSIX path of item 1 of input
    set Answer to item 2 of input   -- This is the value of the Variable_1 variable.

    return filePath & Answer
end run

That said, the return line may not be practical as it's just concatenating two strings at that point, so I suspect this is just for testing to see that it actually can return the two pieces of information.