mdfind - sort by time?
hi,
i'm trying to use mdfind in an applescript i'm working on..
basically, i want to find a recently saved file, by name.. this part is easy and the result comes up very quick (mdfind -name filename)..
the problem i'm having is sometimes i may have multiple files named the same thing and using mdfind -name appears to return the files in a random order..
i'd like them to be sorted by creation time (or modification time or whatever)... is there a way to do that?
what i'm currently playing with is the following:
mdfind 'kMDItemFSName == filename && kMDItemFSCreationDate >= $time.now(-20)'
that works ok for me as the file i'm looking for at this point in the script would have been created less than 20 seconds ago.. the problem with this method however is that it's very slow.. mdfind -name will give me nearly instant results but going in to the metadata takes up to 10 seconds to find the file which is much too slow for the script to work properly..
so, my question is:
is there a way to sort the mdfind items by date?
(if so, i can just get the first item in the list via applescript and go from there)
thanks