I want to create a macro that selects certain file types within a folder (by extension), makes a new folder in that location and moves all selected files of that type to the new folder.
Moving all but the newest file of that type would be helpful too
Optionally, it would be great to run it on a batch of folders at once, say, select the top folder and have it run in all sub folders if it finds the matching file types.nature.
If you do some searching in the forum you should find many examples very similar to your needs.
You can also take a look at Best Macro List -- KM Forum.
With this macro I've used Keyboard Maestro native actions to make it easy for the user to adjust the file-extension and the destination folder name, but I've done the heavy lifting with the shell.
As I mention in the macro notes – do NOT play around with shell scripts without understanding what you are doing – there is the potential to destroy data on your hard drive. Leave the Execute a Shell Script action alone, unless you've got a reasonable grasp of shell scripting.
One more question...
How would I alter it if i wanted more than one file type consolidated? I usually have 2 different file extensions that my audio program creates and I want to put them both in one folder.
Again thanks for all your help!
I tried to duplicate it and run it again with a different extension in the 'zip' line but it throws an error...
How would you keep JUST the most recent file and move all others? Is it pretty simple cause I don't want to keep bugging you but that's the last thing I was hoping to do with KM. I thought if I could get this far I'd be able to get it on my own but I know zip about shell scripting
[edit]
It would only be 1 file type for this action though
Another option you have is to use Hazel, which is built specifically to monitor files and folders and then act on them based on criteria you set up. Many KM users also employ Hazel, and the two apps work well together.
I have several Hazel actions that move and/or rename files after a period of time. For instance, I take a lot of screenshots, so I have Hazel actions that keep screenshots I've taken in the last 48 hours on my desktop, but anything older gets moved to an archive and sorted into dated folders (year and month). Other types of files that land on my Desktop, Downloads, and dozens of other folders have similar do-something-if-file-is-older-than actions.
Okay. I've given you an AppleScript solution for leaving the most recent file-pair in place, but I couldn't resist doing the job in the shell for practice.
It was quite fiddly to get it running on Bash 3.2.57(1), which is stock on Sierra and still stock on Mojave! That silly thing goes back to 2007.
I have Bash 5.0.17(1) on my system – installed via MacPorts (although Homebrew is probably easier to use).
I wonder what's stock on Big Sur...
In any case – I've got this running on both my macOS 10.12.6 Sierra and my macOS 10.14.6 Mojave systems.
I've commented the Bash script reasonably thoroughly, but I haven't gone out of my way to make it easy for the user to modify.
Thanks for all of your hard work on this! I only needed the 1 file type (cpr) saved ion the most recent but I'm sure I can figure out how to alter it (hopefully haha)