A new feature in Keyboard Maestro 8 is the ability to sort the files in the Folder Contents collection by a variety of different conditions:
- by file size
- by creation date
- by modification date
- by date added
- by date downloaded
- by date last used
And you can reverse the order as well. A nice outcome of this is that you can easily find the biggest/smallest newest/oldest file in a folder.
For example, these actions will find the most recently added file in your Downloads folder:
Keyboard Maestro Actions.kmactions (1.7 KB)
As a digression, see that warning triangle in the For Each action? If you click it, it will tell you that you are using a For Each action, but never referencing the variable (Path) within the For Each. Usually, this would be a mistake, but in this case we are really cheating a bit and just using the last value of the index variable. In many programming languages, the variable value after the loop would be unknown, but it is unchanged when you exit the loop in Keyboard Maestro. Perhaps better form (and getting rid of the warning) would be:
Keyboard Maestro Actions.kmactions (1.9 KB)
In any event, you can use this same technique to easily find the first or last file by any of the different conditions which can be an easy way to determine the file you want a macro to operate on.