Re: global variables
Re: global variables
- Subject: Re: global variables
- From: Shane Stanley <email@hidden>
- Date: Thu, 18 Jul 2013 09:39:55 +1000
> Global variables are persistent.
>
> In other words, when you launch an application, the values from the previous launch are remembered.
>
> This means that the application (bundle) is self modifying.
*All* top-level variables are saved after you run a script, provided the script isn't locked. The code is loaded, run, and saved back to disk. It's only in the case of globals and properties that this has any practical consequences, other than (a) modifying the file, and (b) taking extra time to quit if there are large top-level variables.
If this worries you at all, the solution is to keep the top-level of your script minimal, or change its permissions.
>
> Which, in turn, means that use of global variables will interfere with, for example, codesigning and perhaps other security measures used in Lion or Mt Lion.
There's no interference: you just have to set the script's permissions so it can't be modified. This precludes the use of properties to store new values, though.
> Whether a global or property (that is top-level variable) is persistent across run sessions is entirely dependent upon the editing/running application hosting the script.
This is not so -- an editor can only change how they behave when run within the editor. That's not a lot of practical use, except in so far as it may mirror, or not, behavior when deployed. Given that deployment behavior can vary, especially as some people move to code-signing, it's a bit of a messy area.
> These self-modifying apps that Apple's AppleScript Editor makes, isn't Apple breaking its own rules?
The behavior pre-dates any rules -- this year is AppleScript's 20th birthday. Self-modifying files (it happens with .scpt files run from app menus, mostly, too) are the foundation of the way AS stores properties.
> I would think that apps shouldn't modify themselves, and that they shouldn't even create files in the same directory as they are running in, that apps should save their state in the following location:
>
> ~/Library/Saved Application State/<bundle ID>.savedState
No, that's not for apps to play in -- that's what the OS uses for restoring state. If we were starting again, the correct place might be in Application Support, or it might be the property list file in Preferences. The latter has limitations in terms of what sort of data can be stored there from AS, though. And both would be significant changes, in that the present arrangement sees property values travel with a script as it is moved between computers.
--
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>
_______________________________________________
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