Re: BUG: Store script Perversity - it's the Quit handler!
Re: BUG: Store script Perversity - it's the Quit handler!
- Subject: Re: BUG: Store script Perversity - it's the Quit handler!
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 28 Dec 2002 17:10:34 -0800
On 12/28/02 3:52 PM, "Jon Pugh" <email@hidden> wrote:
>
At 3:33 PM -0800 12/28/02, Paul Berkowitz wrote:
>
> Tested: the same bug occurs when all scripts were saved as applications with
>
> SE 2.0 beta. The original "Updater" script (4K text, 72 K as application) is
>
> completely erased, and what's there now when opened in SE 2 or SD 3 is
>
> instead the main script (110K text, 544 K as application) with updated
>
> properties, while the real main script did not save the changed properties.
>
>
>
> It's evidently an AppleScript bug: when the main script is large it seems to
>
> get confused as to which script object it's supposed to store in the
>
> specified file, although it understands which script object's properties to
>
> modify well enough until has to store the script. Bad.
>
>
Here's a supposition.
>
>
Suppose your file variable that you are using, I believe it was:
>
>
updaterScriptFile
>
>
Suppose it never got initialized. It uses some empty file reference. This
>
would often be mistaken for the application resource file and behave like you
>
describe.
>
updaterScriptFile is a script property (originally set to 'missing
value') in the main script. It's quite carefully checked out for validity
each time:
---------------------
if updaterScriptFile /= missing value then
try
get updaterScriptFile -- might have been re-imported, deleted,
moved to other computer
on error
set updaterScriptFile to missing value
end try
end if
if updaterScriptFile = missing value then
set updaterScriptPath to (myFolderPath & "Last Sync Updater.app")
try
set updaterScriptFile to alias updaterScriptPath
on error
set updaterScriptFile to choose file with prompt "Where is the
\"Last Sync Updater\" script?"
end try
end if
--------------------------
But this happens right at the beginning of the main script run. Then the
main script loads yet another script 'assistantScript' but doesn't store
that one. There's never any problem with that one. At the very end of the
main script run, the last called handler 'on FinishOff()' loads, modifies
and stores updaterScript. The very last thing it does is set updaterScript
and assistantScript to null to reduce its own size. Just in case this was
creating the problem (after having already stored the script??), I just
removed those lines setting the two script objects to null. It makes no
difference, except that the perverted Updater script is now 864K in size.
One last twig There's also a quit handler, which doesn't do anything on a
normal quit. It's there in case the user tries to quit from the dock or menu
in the middle of the script run, which was never possible in OS 8/9 with
non-stay-open handlers, but is all too possible an option in OS X. The quit
handler takes care of 24U osax, which otherwise creates a terrible mess with
a daemon that keeps coming back to life and crashing every 10 seconds, and a
couple other things in that case. The quit handler just sets a global
variable 'quitNow' to true, then continues quit. At the very end of the
script that should have no effect on anything.
I just tried it without the quit handler. No problems! It's the quit handler
- which doesn't do anything real - causing the problem! Can you think of
some precaution I can take to prevent this happening on quit?
Here's the quit handler in its entirety:
---------------
on quit -- catch quits from menu and dock
local abOpen
tell application "Finder" to set abOpen to (exists process "Address
Book")
if abOpen then -- Don't if we just quit AB; only if quitting from dock
tell application "Address Book" to save addressbook
end if
try
close progress indicator all windows
end try
set my quitNow to true
(* try -- if not set to null
set assistantScript's quitNow to true
end try *)
continue quit
end quit
-------------------
In a normal quit, abOpen is true, the progress indicator is already closed,
and assistantScript is null (but I also tried removing this try block
completely, as seen here). All it does is is set the global quitNow to
true, then continue quit. It's that 'continue quit' which is putting the
whole main script into the updaterScript somehow.
I've checked and re-checked this. When there's no quit handler, everything's
OK. When there's a quit handler, it all goes wrong. There shouldn't even be
a need for a quit handler with a non-stay-open handler. As has originally
said way back, that's the bug: you shouldn't be able to Quit from the dock
or application menu with a non-stay-open applet. I shouldn't have to provide
a quit handler at all.
Any advice?
--
Paul Berkowitz
_______________________________________________
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.