need help in including files

Does anyone here know how to “include” separate scripts into a single script?

for example, i have 4 scripts named main.applescript ,a.applescript, b.applescript, and c.applescript.

i want to call functions located in a.applescript, b.applescript, and c.applescript from main.applescript. how do i do that? in PHP, i simply need to include “filename.php” and it will be included as if it was a part of the main script.

hope i can get the syntax and steps on how to make it. thanks.

:wink:

Hi bensonang,

AppleScript offers the «load script»-command to include and use external libraries. But afaik it does only accepts compiled scripts (*.scpt) to be loaded. Here is an example:

set mypath to ((path to me) as Unicode text)
set scriptpath to mypath & "Contents:Resources:mylib.scpt"
set mylib to load script (scriptpath as alias)
set x to mylibs's specialfunction()

Also in the Unit Converter sample in:

There is a nice set of handlers for loading multiple scripts.

Cheers,

Craig

i kind of get your point, just a question though, does it pass any global variables loaded in the compiled script?

example, if I put a set of variable declarations in the script, can i use them in another script? thanks.

I guess you are worried about the scope of globals and properties, right? But AppleScript is not all that bad at that :slight_smile:

Here is an example:

Let’s assume that we have a script named «import.scpt» on our desktop. This script contains just one line:


property scriptname : "Imported script"

Now we load this script into our main script with this code:


property scriptname : "Parent script"

set scriptpath to ((path to desktop) as Unicode text) & "import.scpt"
set mylib to load script (scriptpath as alias)

display dialog (scriptname & " calling " & mylib's scriptname & "!")

Our main script also features a property named «scriptname», but it does not clash with the property of the loaded script. You can just access and manipulate them.

Was this of help? I hope so!

Another thing, is there any way to include files in .applescript format rather than compiling them first?
it would be so much better.

thanks.
:smiley:

AppleScript 2.1 Help: load script

I am sorry.

so a .applescript file is considered a text file? am i right? thanks for the info