Here is an example macro that shows how to automatically file images (jpg and jpeg extensions in this case) from the Desktop into the Pictures folder. The macro runs every hour. Obviously, you can adjust the macro any way you want to handle files with different extensions, process different folders, trigger by different means, etc.
This is a very useful macro indeed! I have one challenge though:
The macro doesn’t move the files if there are files with the same name in the folder already. Is there an easy way to make it move them anyway? Maybe by appending a number to the filename?
Yes, Keyboard Maestro will not overwrite an existing file. It doesn’t have any way to move it to a new unique name, so you would have to do this manually. Probably the easiest way would be to move the file to a new unique name first, and then try to move it to the original name (which would fail if the file already existed). Use the Get File Attribute action to get the original name, base named and extension of the file, and then do something like:
Set Unique Name to %Variable%Basename% - %ICUDateTime%yyyy-MM-dd-HH-mm-ss%.%Variable%Extension%
Move to ~/Pictures/%Variable%Unique Name%
Move ~/Pictures/%Variable%Unique Name% to ~/Pictures/%Variable%Original Name%
“most recent” by what definition? Most recently added? No.
Most recently modified or created, yes, Keyboard Maestro can do that by using the For Each action to scan the contents of the folder, and the Get File Attribute modification/creation date to get the modification/creation date of the file, and find the latest one. Something like:
Set Latest Date to 0
For Each file Path in Folder Contents
Get File Attribute Creation Date for %Variable%Path% to variable This Date
If Calculation This Date > Latest Date Then
Set Latest Date to calculation This Date
Set Best Path to text %Variable%Path
Display Text "The last created file is %Variable%Path%"