Re: A Yummy (_Not_) Bug: Gremlin is Rewriting my GUI-Scripting
Re: A Yummy (_Not_) Bug: Gremlin is Rewriting my GUI-Scripting
- Subject: Re: A Yummy (_Not_) Bug: Gremlin is Rewriting my GUI-Scripting
- From: Matt Neuburg <email@hidden>
- Date: Tue, 30 Aug 2005 07:37:33 -0700
On Tue, 30 Aug 2005 01:15:22 -0400, Jonathan Levi MD <email@hidden>
said:
>At 12:48 PM -0700 8/29/05, Matt Neuburg wrote:
>>On Sun, 28 Aug 2005 12:23:12 -0400, Jonathan Levi MD <email@hidden>
>>said:
>>
>>> tell application "System Events"
>>> repeat until ((exists process "MPW Shell") and ¬
>>> (frontmost of process "MPW Shell" is true))
>>
>>> tell application "Script Editor"
>>> repeat until ((exists «class prcs» "MPW Shell") and ¬
>> > (frontmost of «class prcs» "MPW Shell" is true))
>>
>>..the target "System Events" is being replaced by the target "Script Editor".
>>Since Script Editor's dictionary does not define the terminology you're
>>using, you see it as raw code...
>
>I see -- many thanks. Of course that also
>explains why simply correcting the mistaken
>target "Script Editor" and recompiling fixes the
>raw codes as well.
>
>>So...how did the target get changed from "System
>>Events" to "Script Editor"? ..I have seen this
>>happen when a file is moved from one
>>machine to another (and I comment about this in my book). When it happens,
>>it's very annoying, since unless you happen to be the author of the script,
>>you may not be able to guess who the correct target is supposed to be. This
>>is one reason why, in my view, it is actually better to move a script from
>>machine to machine as text than as a compiled script file.
>
>Good point.
>
>>So what did happen to this file? Is this all happening on the same machine?
>
>I believe so, although I can't be 100% sure I
>didn't once have the script on another machine.
>
>>If so, I can't account for it. If you're not running the file from within
>>Script Editor normally, how is it being run? More info is needed.
>
>The problem has always announced itself while I
>was running the script from the Script Menu, but
>that's currently not reproducing the problem. I'm
>afraid this script is turning out to be like the
>proverbial car that keeps malfunctioning until
>it's brought into the shop for repairs.
>
>So, I appreciate your thoughts on this, and I
>will reopen this thread if I can figure out the
>circumstances under which the script bombs.
The reason the problem occurs at all is when you use a literal app specifier
as a tell target, info about where the app is is coded into the compiled
version of the script (something like an alias). That info can go sour if
things are moved or renamed. AppleScript should complain, but instead it
sometimes gloms onto the wrong thing and thinks it's the right thing. If you
have not moved the script or the apps or done any renaming, you might want
to run DiskWarrior on this disk and make sure your directory structure is
not on the verge of collapse... :)
Anyway, one clear way to prevent the problem from occurring again is to code
the application reference as a string variable instead of a literal, and use
a tell block to allow compilation. So:
set s to "System Events"
using terms from app "System Events"
tell app s
....
That way, there is no alias embedded in your compiled code. The "using
terms" block is used only at compilation time, to get the correct raw codes
into the compiled code - and as we have seen, those don't change once they
are there. So the only problem is to make sure that they are sent to the
right app. By making the target in the tell block a variable, "s", instead
of a literal app specifier, we guarantee that it won't mysteriously change.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
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