3

In applescript can you use a variable that was defined in another script? I think you would have something like:

set test to (load script "/tmp/a.scpt")

But how would you pick a specific variable?

1 Answer 1

5

You could use property variables in your external script

e.g, a.scpt:

property foo : "hello world"

...and in the calling script you use the "x of n" style of referencing.

set test to (load script "/tmp/a.scpt")
display dialog (the foo of test)

You can also access the returned result of a handler in the external script.

e.g, a.scpt:

on getChoice()
    set res to choose from list {"one fish", "two fish", "red fish", "blue fish"}
    return res
end getChoice

...and in the calling script:

set choice to getChoice() of test
Sign up to request clarification or add additional context in comments.

3 Comments

I have this in a handler and it says "Expected “end” but found “property”."
@qwertyk31 property variables need to be declared outside any handlers, this is my guess at your issue. They are like global variables so all code in the same script can access them. See this for a breakdown of var types developer.apple.com/library/mac/documentation/applescript/…
When I put the property var outside of the handler the script runs but what I need is to use a handler to run a "choose from list" and get the result in the original script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.