Code libraries (was: parent properties ...scope)
Code libraries (was: parent properties ...scope)
- Subject: Code libraries (was: parent properties ...scope)
- From: email@hidden
- Date: Mon, 5 Feb 2001 13:25:07 -0500
On Sun, 4 Feb 2001 19:49:03 -0800, Richard 23 <email@hidden>
>
Well, this is the reason you don't see large libraries of reusable code.
>
I have no idea why, but the AppleScript's implementation throws up (how
>
messy!) a lot of roadblocks to reusable code, a scripter/programmer's
>
best friend.
>
>
Roadblock: path to me doesn't work properly in Script Editor, so you
>
can't just locate additional required files by looking in the same
>
folder. Since Script Editor isn't scriptable, you can't ask it to
>
tell you which file is open or which file is in which window.
I use libraries of code, and deploy my scripts to two operational servers. I
was also was annoyed by the lack of an import, include, or "with" capability.
Manual hard-coded methods were made difficult because the two servers had
different disk names and paths to the script libraries and other files the
scripts used. I gradually evolved to the following approach to deal with this
situation.
First, I created a folder in the system Preference folder containing aliases to
my library folder. (I was trying to do something similar to Java's CLASSPATH
variable.) Then, I no longer had to rewrite and recompile my scripts, but just
set up the proper alias and everything would be found. This proved useful not
just for script libraries, but for text files (containing user interface
messages or regex commands), preference files, log files, and applications the
script used. (We're running ListSTAR, and have a backup directory, some
previous versions, and sometimes the new beta. 'tell application "ListSTAR
Server"' may target the wrong one when I deploy a script to a new machine, and
ListSTAR looks in the folder where its application file is for all its services,
logs, rules, and address lists. But if I check the preferences file, find my
aliases folder, and start the ListSTAR Server pointed to there, I'm fine.)
I then wrote a handler to look through the route specified by this folder and
alias to load the library I want. But I still had to manually construct the
path to the library that contained that handler, or paste in the handler code.
This is an example of the bootstrap problem.
So, to solve the bootstrap problem, I wrote an osax to do the looking. (I have
no problems with osaxen, since I can install them on the deployment servers.)
I've posted the scripting addition on my web site
http://www.tidalwave.net/~snorton/look.html
Now my code looks like this at the top:
property utilities : load script ( look in preferences under "Project Name" for
"Loadable Scripts:Utility Functions")
property XML : load script (look in preferences under "Project Name" for
"Loadable Scripts:XML Rendering")
set messageFile to (look in preferences under "Project Name" for "Distribution
Messages.html") as alias
I still have to use "tell" to get to the loaded scripts, but I consider that a
feature. That is what a fully qualified name looks like in AppleScript:
'handlerName of library', or 'library's propertyName' Just like
'java.lang.math.PI'
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden