I can use this to sort lists of strings
on Array_Sort_Strings(inputList)
try
set the inputList to current application's NSArray's arrayWithArray:(inputList as list)
set the sortedItems to inputList's sortedArrayUsingSelector:"localizedStandardCompare:"
return (sortedItems as list)
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<Array_Sort_Strings>" & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end Array_Sort_Strings
But it will error on any numeric content. [__NSCFNumber localizedStandardCompare:]: unrecognized selector sent to instance 0x8ae7c1545a4c0538
I can sort lists of numbers with this.
on Array_Sort_Numbers(inputList)
try
set NSArray to current application's NSArray's arrayWithArray:(inputList as list)
set sortedItems to NSArray's sortedArrayUsingSelector:"compare:"
return (sortedItems as list)
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<Array_Sort_Numbers>" & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end Array_Sort_Numbers
But it errors with any text. [NSTaggedPointerString objCType]: unrecognized selector sent to instance 0x8ae7c1545a4c3426
Is it possible to sort lists of mixed data types in ASObjC?
I also tried the following after shaking my fist at google’s AI search results and telling it to get off my lawn.
use AppleScript version "2.4"
use framework "Foundation"
set inputList to {"Banana", "Apple", "Cherry", 3, 2, 1}
Array_Sort_Mixed_Data_Types(inputList)
-->error -[__NSCFNumber _fastCStringContents:]: unrecognized selector sent to instance 0x8ae7c1545a4c0438set sortedArray to theArray's sortedArrayUsingDescriptors:{sortDescriptor}
on Array_Sort_Mixed_Data_Types(inputList)
set NSArray to current application's NSArray's arrayWithArray:inputList
set sortDescriptor to current application's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:true selector:"compare:"
set sortedArray to NSArray's sortedArrayUsingDescriptors:{sortDescriptor}
return sortedArray as list
end Array_Sort_Mixed_Data_Types