Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Finder sort-by-name wrong when have embedded fixed-length hexadecimal characters

This is not the common "leading zeros cause Finder not to sort by name" question:)


Example of how Finder sorts by name (grouping = none) when there are fixed-length strings of hexadecimal in the filename:

sa_mapping_ext_commands_8a0037917f6122005598baf8befa91d1.xml

sa_mapping_ext_commands_8dabe7517f6122005598baf8befa91a7.xml

sa_mapping_ext_commands_9b283fd17f6122005598baf8befa91c0.xml

sa_mapping_ext_commands_33b90f157f6122005598baf8befa9187.xml


Why does it not sort like this?:

sa_mapping_ext_commands_33b90f157f6122005598baf8befa9187.xml sa_mapping_ext_commands_8a0037917f6122005598baf8befa91d1.xml

sa_mapping_ext_commands_8dabe7517f6122005598baf8befa91a7.xml

sa_mapping_ext_commands_9b283fd17f6122005598baf8befa91c0.xml


Posted on Jul 26, 2019 2:55 PM

Reply

Similar questions

4 replies

Jul 26, 2019 4:11 PM in response to jimspot

AppleScript treats text (e.g. filenames) as UTF-8 strings, not hexadecimal. That may have some bearing on the counter-intuitive sort results. On the other hand, Objective-C will sort these name strings in the order you expect:


use framework "Foundation"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions

property NSArray : a reference to current application's NSArray

set foo to {"sa_mapping_ext_commands_8a0037917f6122005598baf8befa91d1.xml", "sa_mapping_ext_commands_8dabe7517f6122005598baf8befa91a7.xml", "sa_mapping_ext_commands_9b283fd17f6122005598baf8befa91c0.xml", "sa_mapping_ext_commands_33b90f157f6122005598baf8befa9187.xml"}

set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
display dialog items of my sort_ascending(foo) as text
set AppleScript's text item delimiters to TID
return

on sort_ascending(ary)
	return ((NSArray's arrayWithArray:ary)'s sortedArrayUsingSelector:{("compare:")}) as list
end sort_ascending


Finder sort-by-name wrong when have embedded fixed-length hexadecimal characters

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.