have names in popupbutton displayed in asending order

Hi

I have a pop button that shows titles of files that have been added to it from a search of a external volume.

What I am trying to figure out is how to have the names of the files displayed in the popupbutton shown in ascending order.

ie: this
40913, 37864, 37844, 40913

should look like this
37844, 37864, 40180, 40913

I have come across this post, but i’m not sure how to adapt it to a popupbutton, or for that matter if it is even possible to adapt it.

http://macscripter.net/viewtopic.php?id=34680

could someone show me how to do this please?

cheers

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.

Ric

gidday Ric

i’m using Stefans suggestion from this thread to get the names into a popupbutton,

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)

Ric

my apologies, i neglected to put the thread relating to Stefan’s suggestion

http://macscripter.net/viewtopic.php?id=37234

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
........

Ric

Hi Rick

thanks for the reply, sorry haven’t replied before now, been a 3 day weekend here.

ok, I tried your suggestion which throws this error in the log

2012-01-31 08:09:51.744 TEST-2[5402:707] -[NSMetadataItem compare:]: unrecognized selector sent to instance 0x4009bcb00
2012-01-31 08:09:51.752 TEST-2[5402:707] *** -[TEST_2AppDelegate queryDidFinish:]: -[NSMetadataItem compare:]: unrecognized selector sent to instance 0x4009bcb00 (error -10000)

cheers

Look at my last post, I edited it yesterday to have the correct code.

Ric

ahh, I used the code from last week that I had copied over.

Just had to remove the “s” from the end of ({sorters}) and it’s a beautiful thing

thanks for that, appreciate it