在再次閱讀您的問題幾次後,我想我已經知道您在問什麼了。您正試圖在您的方法中加載腳本,然後您想調用該腳本中的方法?
如果是這樣的話,我覺得你要尋找的是這樣的...
set HelperScript to load script...
set theResult to someMethod() of HelperScript
編輯: 我還不太清楚,如果你有兩個腳本或一個,所以我已經更新了答案以反映這兩種情況。
雙腳本示例...
property HelperScript : null
on run
try
if not loadScript() then error "Unable to load script"
set rslt1 to SubA() of HelperScript -- This approach assumes HelperScript.scpt is a different script and it contains a method called SubA
set rslt2 to SubB() of HelperScript -- This approach assumes HelperScript.scpt is a different script and it contains a method called SubB
on error errMsg
activate
display dialog "Error: " & errMsg buttons {"OK"} default button 1 giving up after 10
end try
end run
on loadScript()
try
set HelperScript to load script (POSIX file "/Path/To/HelperScript.scpt")
return true
on error
return false
end try
end loadScript
單腳本示例...
on run
try
set rslt1 to SubA() -- This approach assumes your HelperScript is THIS script
set rslt2 to SubB() -- This approach assumes your HelperScript is THIS script
on error errMsg
activate
display dialog "Error: " & errMsg buttons {"OK"} default button 1 giving up after 10
end try
end run
on SubA()
try
-- Do something here
return true -- or some other value
on error
return false -- or some other value
end try
end SubA
on SubB()
try
-- Do something here
return true -- or some other value
on error
return false -- or some other value
end try
end SubB
你能解釋一下你說的「我無法調用SubA()和SubB()...」嗎?你得到的錯誤是什麼,或者什麼不按預期工作,爲什麼。 – ThrowBackDewd