Passing a Variable from Javascript to AppleScript

Post Reply
patgilmour
Newbie
Posts: 6
Joined: Mon Jul 06, 2015 10:56 pm

Passing a Variable from Javascript to AppleScript

Post 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
patgilmour
Newbie
Posts: 6
Joined: Mon Jul 06, 2015 10:56 pm

Re: Passing a Variable from Javascript to AppleScript

Post 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.
Post Reply