On 17 Sep 2015, at 3:50 AM, Christopher Stone <email@hidden> wrote:
This is just one of Shane's handlers repackaged a bit to make it easier for me to process.
Let me just quibble about one part... # Get the NSURLs of items in folder while at the same time getting values for our keys and skipping invisible items. set listOfNSURLs to (theNSFileManager's contentsOfDirectoryAtURL:theFolderURL ¬ includingPropertiesForKeys:keysToRequest ¬ options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) ¬ |error|:(missing value)) as list
<snip>
# Loop through the NSURL list retrieving key values and adding each set as a dictionary/record to the array/list. repeat with oneNSURL in listOfNSURLs (valuesNSArray's addObject:(oneNSURL's resourceValuesForKeys:keysToRequest |error|:(missing value))) end repeat
This looks a perfectly reasonable way to proceed, but there are two traps.
* When you use "repeat with x in y" style loops, you're dealing in references to the items in the list, not the items themselves. Unfortunately there's a bug triggered by trying to render such references as text, which is what script editors do to display stuff in logs. So the code works fine, but it can cause crashes when run from within editors. The more logging or reporting of values an editor does, the more likely it is to have the problem. (Blatant plug: ASObjC Explorer works around this bug.) The usual symptoms are that you run a script three or four times, and the editor crashes. The good news is that the bug is fixed in El Capitan. But until you're doing your editing in 10.11, it's probably better to steer clear of the "repeat with x in y" form when dealing in Cocoa objects.
* The script is going to fail under El Capitan. That's because in 10.11, NSURLs and files are bridged. When you convert an array to an AppleScript list, the bridge converts any items contained within it to their AppleScript equivalents where possible. So when you convert your array of NSURLs to an AppleScript list, the bridge in 10.11 converts the URLs to files («class furl»). This is generally great news in other situations, but not helpful here -- you want to keep URLs.
So the easiest solution is to keep the array as an array, and loop through that. Instead of asking for item i of..., you use the array method objectAtIndex:.The code then becomes something like:
# Get the NSURLs of items in folder while at the same time getting values for our keys and skipping invisible items. set arrayOfNSURLs to theNSFileManager's contentsOfDirectoryAtURL:theFolderURL ¬ includingPropertiesForKeys:keysToRequest ¬ options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) ¬ |error|:(missing value)
--other stuff # Loop through the NSURL list retrieving key values and adding each set as a dictionary/record to the array/list. set theCount to arrayOfNSURLs's |count|() repeat with i from 1 to theCount set oneNSURL to (arrayOfNSURLs's objectAtIndex:(i - 1)) -- Cocoa arrays are zero-based (valuesNSArray's addObject:(oneNSURL's resourceValuesForKeys:keysToRequest |error|:(missing value))) end repeat
|