Re: Changes with El Capitan?
Re: Changes with El Capitan?
- Subject: Re: Changes with El Capitan?
- From: Shane Stanley <email@hidden>
- Date: Thu, 15 Oct 2015 10:08:38 +1100
On 15 Oct 2015, at 9:42 AM, Ron Reuter <email@hidden> wrote:
>
> Can you shed some light on how this fixed the problem? I get that coercing a list to a list is unnecessary and inefficient, but what side effect would it have to cause the code to not work?
Sure. So this:
set theURLs to (thePanel's |URLs|())
returns an array of URLs. But when you append "as list", the array gets converted to a list. Now when you convert an array to a list (or a dictionary to record), the ASObjC bridge automatically converts anything inside it that has an AppleScript equivalent. So an array of NSStrings becomes a list of AS strings.
Before 10.11, the bridge didn't do anything with URLs, so you ended up with a list of URLs. But with 10.11, URLs are bridged to files, so you end up with a list of files instead of URLs. (If you were then passing the list items to a method that require a URL as a a parameter, the bridge would convert the file back to a URL for you, and you'd be none the wiser.)
From my point of view, this has thrown up a couple of interesting and counter-intuitive things I'd never looked into until recently.
First, you can do this:
set theURLs to (thePanel's |URLs|())
repeat with i from 1 to count of theURLs
-- do something with item i of theURLs
Although theURLs is an array, and therefore I previously assumed you would need to use "theURLs's |count|()", in fact "count of" works fine with arrays. And you can say "item i of", rather than "objectAtIndex:(i-1)". It seems to me that for the latter to work, there must be some conversion to a list going on somewhere, but whatever is happening under the hood, in this case the elements aren't bridged.
Second, you can also do this:
set theURLs to (thePanel's |URLs|())
repeat with aURL in theURLs
In this case, if you look in Script Debugger, you can see that aURL definitely contains a *reference* to an item of a *list* of URLs, so so a similar conversion is happening somewhere.
All of which means that, from a repeat point of view, you can treat arrays the same as you treat AS lists. Which is obviously very convenient. However, perhaps more interesting is that, in the few tests I've done, it appears to be quicker to use the AS constructs. And even with very long lists, the "repeat with i from 1 to count of" method doesn't seem to slow down as much as a normal AS repeat; presumably "item i of theArray" is a reference, similar to how using properties can speed up repeat loops.
Shameless plug: All this and more is explained in the latest version of 'Everyday AppleScriptObjC'.
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden