I'll like to run a second applescript with variable from the first Applescript.

If I do a first script to

property myName : "Kevin"

And a second script with :

set remoteScript to (load script "/Users/kevin/Documents/Script/script1.scpt")

set myName to myName of remoteScript

Then everything is fine, the issue is ! The issue is my variable are generated on the first script and so, I can't use property.

I tried to use Global instead but I always having an error

My variables on my main script are mostly set (but not only) from Javascript, I used to use plist to store them but I'm curious and I'd like to try with a another way (also I have probably thousand of variables)


A property is a bit different than a variable - it is more like a getter/setter declaration, where its usage performs the get/set handler of the specified script object and returns the result.

A global also has scope across script objects, but since it doesn’t have a value until one is assigned, you need to run the remote script to do that. In addition, you should probably define the same variable(s) as global in your second script, for example:

First script:

property myName : "Kevin"
global test, one, more

doSomething() -- set globals

on doSomething()
  set test to "testing"
  set one to 1
  set more to {2, 3}
end doSomething

Second script:

global test, one, more

set remoteScript to (load script "/Users/you/path/to/First.scpt")
run remoteScript

log myName of remoteScript
log test
log one
log more

If you're trying to set myName as property myName then you could set property myName : missing value then set its value with set myName to myName of remoteScript

property myName : missing value

set scriptLibrary to (path to documents folder as text) & "Script:script1.scpt"
set remoteScript to load script alias scriptLibrary

set myName to myName of remoteScript

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .