RE: Global variables
RE: Global variables
- Subject: RE: Global variables
- From: Doug McNutt <email@hidden>
- Date: Fri, 9 Mar 2007 21:24:45 -0700
At 13:29 -0800 3/9/07, Stockly, Ed wrote:
>Further, if you do not declare a variable in the top level of the script as a global and run the script as a droplet, then the top level variable does not become a global because the top level is not run. But a global declared in the top level is global to the droplet.
'Tis an interesting thread. I keep hoping I'll learn something from it.
It has always bothered me that globals, and I think properties too, somehow become global to a world far outside of the script being run.
In a truly compiled piece of software globals are "declared" at compile time and they acquire assigned addresses in memory. But AppleScript is a scripting language so it does matter if the code that declares a global does or does not get "run". But then making a droplet is called "save as application" and it is not at all clear just what that means, especially if you are accustomed to "real" compilers and linkers.
It does bother me that property values are supposed to stick between successive runs of an AppleScript. No special reading of a preferences file is required. But if you recompile the values get changed - why? I believe that the "application" is actually re-saved to disk every time it is run and that seems tacky when file system times and dates are important.
I could get used to that but when you toss in globals and discover that they too do the same kind of thing I get terribly confused. Running uncompiled scripts in Script Editor seems to come up with common global memory for everything you do. Using the same name for a global in two different scripts seems to cause problems for me because of namespace confusion. You can get into real trouble by changing the name of a script that you want to work on thinking that you can simply return to the original for the purpose of comparison.
My solution is to use osascript from a command line tool, usually a BBEDit worksheet. That way I'm pretty sure that I'm not being subjected to the funny things that I see otherwise. I think that's because the script gets compiled with fresh memory each time I run it, but I'm not altogether sure of that.
The problem is documentation, or perhaps my unwillingness to study it with the detail required. I learn more from this list than anywhere else, but O'Reilly does get a bunch of my cash.
--
Applescript syntax is like English spelling:
Roughly, though not thoroughly, thought through.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden