• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: alms for an ex-leper
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: alms for an ex-leper


  • Subject: Re: alms for an ex-leper
  • From: Kai <email@hidden>
  • Date: Fri, 24 Jan 2003 11:28:15 +0000

on Thu, 23 Jan 2003 15:17:05 -0500, Bill Metzinger <email@hidden>
wrote:

> I have a droplet/applet that I don't understand it's different behavior.
> ------
> on run
> set A to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
> set KeyList to A
> set KeyListRef to a reference to KeyList
> display dialog (a reference to item 1 of KeyListRef)
> end run
>
> on open
> set A to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
> set KeyList to A
> set KeyListRef to a reference to KeyList
> display dialog (a reference to item 1 of KeyListRef)
> end open
> --------
> If I try it as a droplet first I get the err "Can't make item 1 of
> KeyList into a string"
> When I launch it I get the dialog "1"
> Then trying the droplet again gives the dialog "1"
> Both work until I save changes to the script, then the droplet options
> gives an err until I launch it again.
> Is this normal?
> What I'm getting at is that I have a sorting routine that only wants to
> work as an app and not as a droplet.
> The two seem to handle references differently.

Here's my take on this, Bill - FWIW:

The value of <a reference to item 1 of KeyListRef> is:

-------------------------------
item 1 of KeyList of <<script>>
-------------------------------

To evaluate this (and coerce it to a string for the display dialog command),
AS checks the script's top level for KeyList's value. If it doesn't find a
value, an error occurs.

Whenever you save changes, the script is recompiled - so the value of
KeyList is not yet defined.

If you then use the script as a droplet, KeyList (of <<script>>) has no
value - and the script errors.

However, when you run the script as an applet, the run handler sets
KeyList's value to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Because this value is
set at the top level (i.e. by the run handler) of the script, it may now be
evaluated:

-------------------------------
item 1 of KeyList of <<script>>
--> item 1 of {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
--> 1
-------------------------------

After this initial run, the value of KeyList (of <<script>>) persists[1].
So, when you subsequently use the script as a droplet it refers to KeyList's
top-level value - as set by the _run_ handler (_not_ the value set locally,
by the open handler).

This behaviour continues until the script is recompiled - when the droplet
errors start over.

You should be able to get around the problem by declaring KeyList as a
global variable. However, before you resort to that, are you quite sure
every <a reference to...> is absolutely necessary?

======================================================

[1] If you want evidence of this top-level persistence, try playing with
this version:

------------------------------------------------------
-- global KeyList -- (uncomment for desired behaviour)

on run
set KeyList to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
set KeyListRef to a reference to KeyList
display dialog (a reference to item 1 of KeyListRef)
end run

on open
set KeyList to {"a", "b", "c", "d", "e", "f", "g"}
set KeyListRef to a reference to KeyList
display dialog (a reference to item 1 of KeyListRef)
end open
------------------------------------------------------

--
Kai
_______________________________________________
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.

  • Follow-Ups:
    • Re: alms for an ex-leper
      • From: Kai <email@hidden>
  • Prev by Date: Re: alms for an ex-leper
  • Next by Date: Re: alms for an ex-leper
  • Previous by thread: Re: alms for an ex-leper
  • Next by thread: Re: alms for an ex-leper
  • Index(es):
    • Date
    • Thread