Re: Inheritance and Loaded Libraries
Re: Inheritance and Loaded Libraries
- Subject: Re: Inheritance and Loaded Libraries
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 28 Oct 2004 02:03:00 -0700
Title: Re: Inheritance and Loaded Libraries
On 10/27/04 5:23 PM, "David Weiss" <email@hidden> wrote:
I'm totally confused. Why doesn't this work?
I've got a 3 part AppleScript system:
Exhibit 1 - The Script Runner: An AppleScript Appliction
property XLib : missing value
on runScript(theScript)
set XLib to (load script ("Macintosh HD:Users:davidweiss:Desktop:ALib.scpt" as alias))
run theScript
quit
end runScript
Exhibit 2 - The Script Library: A Compiled Script
on runTest()
say "a Lib"
end runTest
Exhibit 3 - The Script: A text script
script myScript
property parent : application "ScriptRunner"
-- my XLib's runTest() -- fails!
-- runTest() of my XLib -- fails!
tell my XLib to runTest() -- works!
end script
tell application "ScriptRunner" to runScript(myScript)
----
Why do
my XLib's runTest()
runTest() of my XLib
both fail, but
tell my XLib to runTest()
Hi, David
Well that certainly is interesting.
- I don't think that a script object's parent can be an application. I think it can only be another script, or AppleScript. So the property declaration in Exhibit 3's script myScript is not doing anything. Remove it, and everything is exactly the same. Compiling Exhibit 3 and running it still works. The 'parent' property was doing nothing.
- Note it only works if you've saved Exhibit 1 as a Stay Open application (in either case - parent or no parent). Otherwise you get a "Connection is invalid error". Notice that nothing quits though. You have to change 'quit' to 'tell me to quit' - then the application quits after saying "a Lib".
- When Exhibit 3 is compiled and run, it tells application "Script Runner" to execute its handler runScript(theScript). You could simply load script alias "Mac HD:Script Runner" instead (wherever it may be located) which is usually more efficient, but OK - if you have some reason to use it as a stay-open application, this works.
- application "ScriptRunner"'s runScript(theScript) handler first sets its property XLib to load ALib.scpt. OK. Then it's supposed to run the myScript script object it was passed. myScript contains a reference to XLib. Even though that reference meant nothing at the time you compiled Exhibit 3, now that XLib has been defined as a property by Exhibit A to be ALib.scpt it accesses the new value for XLib as a loaded script.
- XLib is now a loaded script object. It's true that in every other context I know you can call a script object's (including a loaded script's) handler either by 'tell' or by 's or 'of'. But not here - you've found an exception.
The exception must have something to do with the rather amazing state of affairs in 4 above: at the time you compile Exhibit 3, XLib is an undefined variable - something that's permitted in script objects. Yet when ScriptRunner (Exhibit A) runs its runScript handler it can identify its myScript parameter's XLib with the script it just loaded. I imagine that 'tell' makes it review XLib's handlers anew and execute it. If you have a property saved in XLib, the other methods can extract the property's value - they just can't call handlers. Yet in other contexts - simply loading a script file - you can call its handlers by any of the ways you specify. Very oddd.
Maybe Chris can enlighten us. Or maybe it's something Matt has run into - although it's not in his book.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden