Re: Reusability / inclusion of Apple Scripts?
Re: Reusability / inclusion of Apple Scripts?
- Subject: Re: Reusability / inclusion of Apple Scripts?
- From: Michael Grant <email@hidden>
- Date: Wed, 12 May 2004 09:59:48 -0500
On May 12, 2004, at 9:03 AM, Cliff Pruitt wrote:
I know for those of you who have been at this a while, this will be no
big deal at all, but yesterday was the first time I was actually able
to write a script of any real complexity & usefulness between several
applications and I'm pretty excited about that. More of the details
of AS are starting to sink in & its encouraged me to get more into
looking at things like Script Objects & whatnot. So heres the
question:
You're at the stage where you'll learn a LOT from the new Matt Neuburg
book (AppleScript: The Definitive Guide). Highly recommended!
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
--
The government doesn't want you to know... e-mail doesn't work. At all.
It's a scientific impossibility.
_______________________________________________
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.