Re: How to get the number of items in a selected Folder ?
Re: How to get the number of items in a selected Folder ?
- Subject: Re: How to get the number of items in a selected Folder ?
- From: Shane Stanley <email@hidden>
- Date: Fri, 27 Nov 2015 09:41:30 +1100
On 27 Nov 2015, at 1:46 AM, Thomas Fischer <email@hidden> wrote:
>
> I played around with your solution and found that I cannot save it as script (on Yosemite).
I think Yvan's asked the important questions -- whether it compiles, and therefore if you have version 1.3 or later of ScriptLib installed. But let me make another point which might explain things.
In short: you generally need to re-compile ASObjC scripts before you save them.
The longer version: When you save a script, the values of any top-level variables are saved along with it. This is the basis of how property persistence works, among other things. But in ASObjC, when we say that a variable contains, say, an NSString, what it really means is that the variable is storing a pointer to the string: the "«class ocid» id «data optr00000000708ED4A5E27F0000»" you might see in the log is an AppleScript object, and that optr represents the address in memory where the string lives.
Clearly, saving a pointer would be pointless -- in fact it would be dangerous -- because anything could be at that memory address next time you run the script. So pointers aren't saved. Unfortunately, most editors don't make allowance for this. You have to know to compile before saving.
Given that there are now several other situations where the existing method of property persistence is inappropriate -- code-signed applets, apps that use GUI scripting, and others -- there's a good argument that script editors should allow for the change somehow. ASObjC Explorer, for example, keeps the compiled version you see and save separate from the version that is run, thus avoiding the problem (and the inherent insecurity of saving potentially important information in scripts for all to see).
The problem then becomes how to handle persistence of values without modifying the script file itself. It would be nice to see AppleScript itself tackle that issue, but it turns out there's a decent ASObjC solution to that, too.
--
Shane Stanley <email@hidden>
<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