• 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: Newbie Question: Script Objects (1)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Question: Script Objects (1)


  • Subject: Re: Newbie Question: Script Objects (1)
  • From: has <email@hidden>
  • Date: Tue, 18 Feb 2003 03:33:01 +0000

Simon Brown wrote:

I'd like to know if my assumption that properties declared at the root level
of script objects persist only as long as the parent script app ...

Happily, this is incorrect (as others have pointed out). Script objects can survive the death of their host process.

A few random observations:

- Every compiled script is itself a script object.

- A script object is pretty much just a bunch of named slots containing handlers and other objects/values. Some are declared using 'on foo()...end foo', others with 'script bar...end script', and the rest as 'property baz : ...', but it's all the same at the end of the day.

- Properties of a script object retain their contents until the script object is destroyed.

- AppleScript has good, transparent object persistence (one of its nicest features). A [copy of a] script object can be preserved almost indefinitely by storing it to disk when not in use. (Some applications take care of this for you, e.g. script editors, stand-alone applets.)

--

I would also like to know why only one of the following scripts works,
dependent on the position of the script object in the script:

Because the AppleScript compiler is a bit brain-dead. Most variable/property bindings are resolved at compile-time for performance reasons [1]. Alas, the compiler doesn't check the entire source code before deciding how variables are scoped - it just makes it up as it goes along. Presumably a design oversight that, like a lot of things, has just never been fixed.

So it's up to you to make sure your global/property/script is positioned ahead of the code that uses it, or invoke them dynamically (e.g. 'get MY scriptProperty' instead of 'get scriptProperty') which is slower and messier and just a bit pointless.

Easiest solution is just to write your code with properties, global variables and script objects declared first, then the handlers that use them.

-------

Andrew Oliver wrote:

Global variables are reset on each run:

Incorrect. Globals persist too. But this persistency is pretty useless in practice, since you can't give them an intial value at compile-time (think about it). All they really do is bloat saved scripts.

-------

has


[1] By contrast, handler calls are always resolved dynamically, which is why you can put your handlers in any order you like.
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.
  • Prev by Date: Re: Newbie Question: Script Objects (2)
  • Next by Date: Mail to recipients
  • Previous by thread: Safari and system AppleScript menu
  • Next by thread: Mail to recipients
  • Index(es):
    • Date
    • Thread