Page 1 of 1

Passing a Variable from Javascript to AppleScript

Posted: Wed Apr 13, 2016 10:44 pm
by patgilmour
Hi,

I have a flow where I use a script (Javascript) to pull some variables from some job metadata.

I then want to pass these variables to an AppleScript so that I can do some AppleScript commands.

Is the best way to do this to have two script elements, as in:

- Use Scripting Element 1 (Javascript) to get my variables
- Write them as PrivateData into the job
- Use Scripting Element 2 (AppleScript) to get my variables from PrivateData

I appreciate I can get variables from metadata using Applescript of type:

Code: Select all

set myEmailSubject to evaluate variable as string of j variable "[Metadata.Text:Path=\"/email/subject\",Dataset=\"XML-FromEmail\",Model=\"XML\"]"
...but I have a lot of stuff I want to do in Javascript before returning the PrivateData, so I really prefer to use Javascript at the first stage.

If the above is the correct approach, how do I read a privatedata var in AppleScript.

For example, let's say the Javascript returned:

Code: Select all

job.setPrivateData("EmailSubject", emailSubject);
How would I read this variable in the Applescript scripting element?

Thanks, Pat

Re: Passing a Variable from Javascript to AppleScript

Posted: Fri Apr 15, 2016 4:32 pm
by patgilmour
Quick answer to my own question: you can read private data in Applescript with the following:

Code: Select all

set varNewForAppleScript to evaluate variable as string of j variable "[Job.PrivateData:Key=\"varForAppleScript\"]"
The [Job.PrivateData:Key...] part is the standard tag that is created when you use "Insert Variable" in Switch dialogs.

Passing a Private Data variable into the flow with a Javascript Script element then reading it later with a Applescript Script element does work. I still don't know if this is a recommended way of handling things however.