Possible Duplicate:
Import AppleScript methods in another AppleScript?
Is there anything in AppleScript that can be used like the #include
directive in C?
For instance:
INCLUDE_DIRECTIVE "Path/To/Applescript.scpt"
//Some AppleScript code here
Absolutely you can do this, and there are two variations. The first loads the entire script:
Script Foo.scpt
set theBar to "path:to:Bar.scpt" as alias
run script (theBar)
Script Bar.scpt
display dialog "Bar"
--Result: A window that displays "Bar"
The second allows you load a script and call specific methods within that script:
Foo.scpt
property OopLib : load script POSIX file "/Users/philipr/Desktop/OopLib.app"
tell OopLib
set theResult to Oop(1)
display dialog theResult
end tell
--> result: Window displaying "Eek: 1"
OopLib.scpt
on Oop(Eek)
display dialog Eek
return "Eek: " & Eek
end Oop
Use something like this to load the script
set scriptLibraryPath to (path to scripts folder from user domain as text) & "myScript.scpt"
set scriptLibrary to load script scriptLibraryPath as alias
Then to access a subroutine in that script do this...
set myValue to someMethod() of scriptLibrary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With