I'm trying to work out how to sort a list of filenames not by any text in the filenames themselves but by properties of those files. In particular I want to be able to sort on, separately, the position
property (which has x and y components) or the comment
property, which will be set previously.
For simplicity, I've been trying to do the comment
version first in hopes that understanding how that works will illuminate how to do it for row and column positions instead of a single value.
I will be setting the comment
value for each file by stepping through each of my Mission Control Desktops where I have placed a file on each desktop. I will get the number for the desktop and save it in the comment
property for the file that is on that desktop. So when I sort the list of files by the comment
value, it will be sorted into the order that matches the Mission Control Desktop order.
I haven't yet worked out how to sort that list of files according to the specific property. I know, conceptually, about various sorting algorithms, but making them work in AppleScript or KBM is my challenge here.
The second kind of sort is on the position
property. For the Icon View of a Finder window, each file has a position
property that is the xy position of the center of the icon in the Finder window. When those icons are positioned manually and then the Clean Up function is run, it aligns the icons to a grid. I want to list those files, in LtR reading order, across each row and then down row by row.
The ultimate goal is to verify that my arrangement of file icons in the Finder window (the position
property) matches the order of the files as they have been placed in the various Mission Control Desktops (the comment
property).
If I manually rearrange the order of the Mission Control Desktops (e.g., to put a project desktop next to my To Do List desktop) I will need to remember to manually rearrange the Finder window icons, so I want an alert that they don't match. I may eventually also be able to automatically rearrange the icons in the Finder window to match the Mission Control Desktop order and I will need to know when such an update is needed.
Where I'm stuck right now is how to write the sorting functions so that it arranges the list of files based on the specified property, either the one-dimensional comment
number or the two-dimensional position
.
Can anyone point me to sort functions that I might use as examples?