passing applescript list to workflow

this seems like such an obvious thing, but I haven’t seen anything on it anywhere. so here’s the problem: I can get a list of newly arrived emails from Mail into applescript using Rule actions, and there’s a neat little automator action that automatically downloads attachments from emails. you’d think would be some way to get the list of emails out of my applescript into the automator workflow, but I can’t find a hook for it. does someone know how to do this?

I mean, I can think of a few ways of getting around the issue (e.g. have the script drop the list into a temp file or a script object, and write a ‘run applescript’ action to extract it again and pass it on to the rest of the workflow), but that’s kinda clunky, and it bugs me that there doesn’t seem to be a simpler way to do it. any insights welcome. :slight_smile:

Automator has a looping function, but it only operates on either a set number of repetitions, or a specified amount of time. If you have a workflow that generates a list, you have no choice but to either write it to a file for further processing, or create another Run AppleScript action to deal with the items in the list.

Good Luck,

you misunderstood the question, I think. what I’m curious about is how you get an applescript list from outside of Automator to be inside of automator. look at the problem again: a list of mail messages generated by Mail in an applescript, passed (somehow) into an automator workflow for further processing. how do you do that? in other words, I know I can use applescript to open an application or a script application and pass it parameters; how can I use applescript to open a workflow and pass it parameters?

incidentally, I’ve already resolved the Mail issue itself, so no need to comment on that, but I’d still like to know how to do this in general.

Ahhh. I see. Sorry about that. I believe that the only way to do it would be to save the Automator Workflow as an application, and have it read the data from a file. To launch it, the starting AS would write the data to said file, then launch the Automator app.

If the list in question is a list of files, consider attaching the Workflow to a folder as a Folder Action, and send the list of files there, automatically triggering the Workflow.

wow - funky things you learn if you poke around. apparently there’s a unix command called (go figure) ‘automator’ that will run automator workflows, with options for setting inputs and variables. so while I still can’t figure out how to do it straight from applescript, I could write a command like:

automator -i alpha beta gamma -D thisvar=delta thatvar=epsilon ~/test.workflow

and then run it from do shell script - that would run the test workflow with {“alpha”, “beta”, “gamma”} as the input and the variables thisvar and thatvar set to delta and epsilon.

News to me. Good luck, and please post back if you get a working solution.

this solution works, though apparently you have to be careful about how you structure the list you send to the command line (I needed help from the discussion forums over at Apple Support to figure it out :D). it needs to be NEWLINE delimited, and it doesn’t like ‘\n’. so to send a list to a workflow you need to do it like this:

to run_workflow given inputs:inputVars, workflow:workflowPath
	set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
	set theWorkflowInputs to inputVars as text
	set AppleScript's text item delimiters to tid
	set cmd to "automator -i '" & theWorkflowInputs & "' " & workflowPath
	return do shell script cmd
end run_workflow

it would take a little more work to include workflow variables too (because of the VarName=Value format), but it should be easy to adapt.