I’m wondering if anyone can explain this behavior of array formatting inside an Automator workflow.
I am using
NSUserAutomatorTask to launch an Automator workflow from a macOS app.
I’m passing in variables via the
variables property. I’m passing both a String and an Array value variable in the variables dictionary.
Inside the Automator workflow I will then use
Get Value of Variable actions to grab the variables that were set on the
NSUserAutomatorTask and pass the variables to subsequent Automator actions:
In the Mac app the Swift code looks like this:
let workflow = try! NSUserAutomatorTask(url: url) workflow.variables = [ "singleFilePath": "/image1.png", "multipleFilePaths": ["/image1.png", "/image2.png"], ] workflow.execute(withInput: nil)
I’m able to print out the variable values in an alert via an
Ask for Confirmation action:
String variable’s value is a simple string:
[String] array variable’s value is wrapped in parentheses and each item is quoted:
( "/image1.png", "/image2.png" )
My control is to write a “normal” workflow, rather than variables, and use a Get Specified Finder Items action + View Results action:
The array/list format is exactly the same as when I use the variable.
I now run the pictured Automator workflow that first gets a variable’s value and then attempts to open those Finder items.
singleFilePath var works. It’s passed on to the Open Finder Items action, and that file is opened by the default application.
multipleFilePaths in the same manner does not work. No files are opened. Automator displays the error:
The action “Open Finder Items” was not supplied with the required data.
The action is “Open Finder Items”, so there must be some way to pass multiple file paths to this action.
My questions and solutions in order of preference are:
Why is the default variable array/list format not working when passed to the subsequent action? Is there any way to pass or parse the array variable in a compatible format?
Can we use a single
Run AppleScriptaction to reformat the array variable into a format that can be passed to subsequent Automator actions? (I’d like to continue to chain Automator actions rather than run pure AppleScript).
Thank you for any help you might offer!