A Few New Macros for Keyboard Maestro: Folders and Clipboards

February 07, 2018 by Gabe | [mmd] |

I’ve been doing quite a bit of macro maintenance in my Keyboard Maestro collection. That also means I’ve been writing new macros because once that KM window is open I tend to fall down a lot of rabbit holes.

Every January I need to create a sequence of numerical month folders on a couple of servers. It’s easy but repetitive work. This is a good niche for Keyboard Maestro. This macro accepts a starting number and ending number and creates zero padded folders like 01, 02, 03.

Monthly Folders

Here’s the macro:

Folder Macro

The most interesting bits in this macro are the decimal formatting at the start of the “While” loop and the "until" calculation at the end of the “While” loop.

KM has a several functions for formatting strings but the simple “%Dec2%%” function is nice. It specifies that a variable that is a decimal value should be minimally two characters long. This turns “2” into “02.” You can do additional padding too. “%Dec4%%” would create “0002.”

The “while” loop continues until I’ve created the right amount of folders.

Another thing I find myself needing more often than you might expect, is the path of the current Finder folder. This is not hard but I like the KM way. Here’s the macro:

Path Macro

It’s neat because Keyboard Maestro has a built in variable that is just the current Finder view which is just the path of the view. I go two more steps than I need to if I just wanted to copy the path. I also display the path in an alert just for sanity. No need to check the clipboard.

Here’s one that’s particularly fun even if it lacks good error handling. Ever take a screenshot to the clipboard and then decide you’d rather have it as a file in a folder? This macro checks the clipboard for an image and if it exists then it saves it as a file in my “ScreenShots” folder as a jpeg.

Clipboard Macro

To do it right, I should probably make sure it’s really a jpeg and yada, yada, yada. I trigger this manually and the worst that would happen is that I try to save something that can not be saved as a jpeg. I’ll fix it up next year when I clean out my macros.