Re: Who has that property?
Re: Who has that property?
- Subject: Re: Who has that property?
- From: has <email@hidden>
- Date: Fri, 11 Nov 2005 14:17:57 +0000
Axel Luttgens wrote:
> > 1. Enquire about your context pollution problems on LNS's SD mailing
>list and/or their support desk. If SD is the culprit as you suspect
>(it's definitely not AS's doing), [...]
>
>it could well be that he doesn't face context clashes due to SD, just an
>old standard AS behavior that gets often overlooked when doing trials in SE.
>
>That behavior may be described by this rather elusive excerpt from the
>ASLG: "The default parent property for any script that doesnÃt
>explicitly declare one is the default target applicationóusually, the
>application that is running the script, such as the Script Editor".
Yes, you're (semi) right. AS reports the script's parent as 'AppleScript' so any operation not handled by the script is passed to the AppleScript component to deal with. I simply reported this without thinking any further. However it's not the whole story as the AppleScript component itself can delegate operations to another target, one specified by the host process. My bad for forgetting all about this bit - it's not like I don't know my way around OSA well enough by now, so I must have just been asleep at the wheel at that point.
The default delegate for the AppleScript component is actually determined by the host process, which usually assigns itself for convenience. This isn't an AS feature, however, it's an OSA feature. And how it gets used is decided by the application, so I was right that it's not AS's doing - it's the application's.
>So, let's see if this makes some sense with the "run script" command.
[snip code]
Your demonstration doesn't work as-is because lib.scpt never loads sublib.scpt (presumably an oversight in the posted code). Easily fixed by putting the 'load script' line into the test() handler though.
Anyway, here's a much simpler version of the same test:
------- lib.scpt -------
property x : "lib"
on test()
display dialog "" & parent's x
end test
------------------------
------- main.app ------
property x : "main"
set lib to load script alias "MacHD2:Users:has:test:lib.scpt"
lib's test()
------------------------
As you say, running main in a script editor results in the expected error when AS tries to evaluate "parent's x". Running main.app as an applet results in a dialog saying "main", which is makes no sense, but I think I see what's going on.
What appears to be happening in the applet is that lib.scpt is delegating the 'parent's x lookup' to the AppleScript object. The AppleScript object is unable to resolve this lookup itself, so it delegates it to the default target application - the applet shell. The applet shell automatically delegates it to its main script to take care of, because forwarding all property lookups and handler calls to an embedded script what applets are designed for. The same test fails in a script editor, because script editors aren't designed to do that. Interestingly enough, it also fails for a bundle-based applet, though at the moment I don't know why.
Basically you've found a loophole that exists due to the way some applet implementations use OSA to do their thing. Although it should be regarded as a bug (feel free to file a report on it), not a feature, and its deliberate use avoided.
This could well explain why the OP's clever trickery is backfiring, assuming whatever context he's running in performs the same semi-circular delegations. If the problem's occurring in an applet then he needn't bother asking LNS as the answer's already found. If it's occurring in SD then it may be that SD uses similar tricks for some reason or other, but it'd be worth finding out for sure.
Anyway, my second recommendation to the OP still stands: ditch the existing library loading system because it's hacky and plain bad design - and therefore an open invitation for things to blow up - and use one that works, e.g. SD's proprietary library binding system or AppleMods' vanilla, open-source Loader system. (I'm sure there are SD users here who can advise on the former, and I can certainly vouch for the latter.)
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
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