How are you getting those numbers into the popup? Are you doing it with bindings. That’s the easiest way. You have the file names in an array that is the content array for an array controller. You can then use the array controller’s auto rearrange content method to keep the names in order.
I’m not seeing anything in this thread from Stefan. I don’t know what’s going on – when I first saw your post, I thought I saw it had 6 posts, but when I clicked on it there was only the one you posted today at 2:47:57, and now There are only the three (four including this one)
It looks like from Stefan’s method that foundItems is an array, so you could sort it before you do the loop to add the items to your popup.
So:
.........
set foundItems to theNote's |object|()'s results()
set sorter to current application's NSSortDescriptor's sortDescriptorWithKey_ascending_("kMDItemFSName",1)
set foundItems to foundItems's sortedArrayUsingDescriptors_({sorters})
repeat with anItem in foundItems
........