Re: Reusability / inclusion of Apple Scripts?
Re: Reusability / inclusion of Apple Scripts?
- Subject: Re: Reusability / inclusion of Apple Scripts?
- From: Cliff Pruitt <email@hidden>
- Date: Wed, 12 May 2004 16:08:03 -0400
Hey thanks for the great info! Can I follow up & ask, what exactly is
happening & is 'script_file' a reserved AppleScript variable or object
or something (sorry, I still get my vocab mixed up). Also does this
RUN the referenced script or load it into the current script. For
example if Script_B is just a bunch of subroutines or Script Object
definitions, and if I load Script_B into Script_A, does Script_A have
access to those subroutines, or is Script_A just sending system
messages to tell Script_B to run. Can Script_A load Script_B, and also
load Script_C, Script_D, and Script_E?
Thanks a lot. I've been enjoying AS this week. Its been nice to make
some headway. ;-)
- Cliff
On May 12, 2004, at 1:15 PM, Michael Grant <email@hidden> wrote
--__--__--
Message: 7
From: Michael Grant <email@hidden>
Subject: Re: Reusability / inclusion of Apple Scripts?
Date: Wed, 12 May 2004 09:59:48 -0500
To: AppleScript-Users list <email@hidden>
On May 12, 2004, at 9:03 AM, Cliff Pruitt wrote:
If I write Apple scripts (not in AS Studio), and want to use something
like a script object, does the script that is running have to contain
the object definition inside of that script, or is it possible to
create "libraries" and include them in the running script like you can
in OOP languages. If so does the other "library" script have to be
open and running in order to be accessed? Does the "library" script
have to be saved as an application?
I guess my real question is how, if there is a way at all, do you guys
work with multiple scripts or script objects outside of AS Studio?
How do you reference them?
Below is a script that runs every night to back up certain files on my
system. I have a couple dozen copies of the script differing only in
the properties at the start; they all call the same library script that
does the actual compression and backup routine according to the
parameters passed to it. (One of these days maybe I'll consolidate them
into a single |berscript that just reads the parameters from a text
file. I suppose I should update "Finder" to "System Events" too....)
As you can see by the code, a script can load external library scripts
stored elsewhere on the system. The library scripts don't need to be
saved as applications.
I have very little experience with Studio, so I'll leave that part to
others.
Michael
property archiveScript : "BDScriptLibrary:Archive.scpt"
property archiveNameRoot : "ToDo"
property originalSpec : "Budapest:Users:mgrant:Documents:to do:"
property backupSpec : "Bratislava:Backups:To Do Backups:"
property timeoutLength : 390
property keepArchives : 2
set archive_script to loadScript(archiveScript)
tell archive_script to archiveItem(archiveNameRoot, originalSpec,
backupSpec, timeoutLength, keepArchives)
on loadScript(theScript)
try
tell application "Finder" to set script_file to ,
(((path to home folder) as string) & "Library:" & theScript) as
alias
on error
try
tell application "Finder" to set script_file to ,
((name of startup disk) & ":Library:" & theScript) as alias
on error
try
set script_file to (choose file with prompt ("Where is the library
script " & theScript & "?"))
on error
display dialog "Sorry, master script not found!"
return
end try
end try
end try
return (load script script_file)
end loadScript
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.