How to reference a property from a different applescript file

Hi all!

My application spans over 4 applescript files. I want to access some properties that’s in one.applescript and use them in two.applescript.

Can anyone tell me how to do this? I thought making them into properties would make them global?


The only way I can think off (and I’m very much a noob, so beware) is to make the properties somewhere available in the interface, since that’s the thing that binds all the different applescripts together.

In other words set the contents of an invisible text field to the property you want to share amongst several scripts and read/write them from that text field.

Alternatively, there’s the magic of copy and paste to turn your four applescripts into one.


use AppleScript’s capabilities to load compiled script as script objects.
Then you can access the properties and call the handlers

Create script #1

property myValue : "World"

on saySomething(what)
	say what
end saySomething

save it as “Value.scpt” on desktop

Create script #2 and run it

set theScript to ((path to desktop as Unicode text) & "Value.scpt")
set myScript to load script alias theScript
myScript's saySomething("Hello" & myScript's myValue)
--> spoken "Hello World"

I got it to work, partially …

I have something like this going on in script 1:

property myshellscript : ""

on awake from nib theobject

set myshellscript to "some shell script"    <- is a shell script!

end awake from nib

on thefunction()
do shell script (myshellscript)
display dialog(myshellscript as string)
end thefunction

when I load this script into the second script, and then try and use thefunction(), my display dialog appears! That means that the script was successfully loaded. However, the dialog is empty! Which means that through the script object, it can’t find the myshellscript variable …

Any ideas?

PS I’ve already implemented a crude fix which is to have the whole thing pasted into the second script to work out the shell script again … Although for the future I’d like to know how you could get around this!

Thanks a lot guys!

-Mel :wink: