# Make a sort descriptor that describes the key to sort on
set theDescriptor to
current application's
NSSortDescriptor's sortDescriptorWithKey:(sortKey)
ascending:sortAscendBool # MY MOD to allow true or false
# Sort the array
set theSortedNSArray to
valuesNSArray's sortedArrayUsingDescriptors:{theDescriptor}
if returningAsListBool =
true then
# Extract just the paths and convert to an AppleScript list
return (theSortedNSArray's
valueForKey:(current application's
NSURLPathKey)) as list
else
# Or if you only want the most-recent, use this instead of the previous line:
if sortAscendBool then
### THIS WORKS -- THE LAST FILE PATH IS RETURNED ###
return (theSortedNSArray's
lastObject()'s
valueForKey:(current application's
NSURLPathKey)) as text
else
### MY MOD -- THIS RESULTS IN THE ENTIRE LIST BEING RETURNED ###
return (theSortedNSArray's
firstObject()'s
valueForKey:(current application's
NSURLPathKey)) as text
end if
end if