从另一个脚本获取变量

Qwe*_*tie 3 variables applescript

在applescript中你可以使用另一个脚本中定义的变量吗?我想你会有类似的东西:

set test to (load script "/tmp/a.scpt")
Run Code Online (Sandbox Code Playgroud)

但是你如何选择一个特定的变量呢?

ada*_*amh 6

您可以在外部脚本中使用属性变量

例如,a.scpt:

property foo : "hello world"
Run Code Online (Sandbox Code Playgroud)

...在调用脚本中,您使用" x of n "样式的引用.

set test to (load script "/tmp/a.scpt")
display dialog (the foo of test)
Run Code Online (Sandbox Code Playgroud)

您还可以在外部脚本中访问处理程序的返回结果.

例如,a.scpt:

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

......并在调用脚本中:

set choice to getChoice() of test
Run Code Online (Sandbox Code Playgroud)