Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#include like directive in AppleScript [duplicate]

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
like image 283
Mark Szymanski Avatar asked Jun 12 '10 03:06

Mark Szymanski


2 Answers

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
like image 191
Philip Regan Avatar answered Sep 23 '22 05:09

Philip Regan


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
like image 38
regulus6633 Avatar answered Sep 22 '22 05:09

regulus6633