My first decent macro and a whole bunch of questions

Hey, Everyone!

I've been lurking around here for the past several months, long enough to learn a lot and steal even more. I'm a non-computer guy trying to solve various annoyances and reduce the number of mouse clicks and keystrokes I have to make in a day, and I've been having a blast learning how to use Keyboard Maestro to do it.

After creating many, many very simple macros I decided to tackle something slightly more complex and, lo and behold: it actually works the way I intended.

To any of you experienced folks will be able to see that this macro simply allows the user to add or remove tags from files and folders selected in the Finder.

I've started tagging all my stuff so Hazel can sort it, so this little macro saves me ridiculous amounts of time.

But I'm not just posting it because I am quite pleased with my newly acquired rudimentary skills. I have a bunch of questions and I'd love some feedback from the community here.


  1. Did I just duplicate something that someone else has done that I might have looked at, used, or stolen from? I try to take every opportunity I can to learn from what other people are doing, since there are alway things I've not considered. Because I don't really know very much.

  2. Are there better ways to do any of these steps?


In the "Clear Variables" group, is there are more compact way to set all of the variable I'm using to null so that I don't accidentally have any left-over junk from a previous operation of the macro?

Can anyone tell me, or tell me how to find, how to write an Applescript or JXA command to get the selected file paths and store them in an array or a list instead of using the Set Variable action?

And can someone explain to me how the Set File Attribute action as it is used here even works? I don't what's going on with the whole "Get Path of Each File in Selection"action.

Do I have any unnecessary things in here?

What would you do differently?

I would say thanks in advance, but I already owe you guys a thank you for all the ideas I've stolen so far. So, thanks. And thank you to Peter Lewis for creating such a crazy tool. I can't believe I used to live without it.


Keyboard Maestro “Add/Remove Tags” Macro

Add-Remove Tags.kmmacros (13 KB)


Nice! Doesn't it feel great? Even if your macro is inefficient it is yours and you can always improve it later. (I sweep through my macro library every few months and archive things I no longer use, tag them for improvement later, and frequently simplify them with new tricks I've learned)

I think the standard for cleanup is setting variables to %Delete%

Setting them to an empty field leaves them hanging around in the list of variables, while %Delete% deletes them from the list of variables. You can see this in your variables in Keyboard Maestro Preferences:

Neat! So I suppose there’s no reason to keep the variable around if the macro is creating it every time it’s called. That makes sense. Thanks so much!

You are right. It does feel good.

1 Like

Setting a variable to empty will remove it from the list of variables in the Variables preferences pane.

Setting it to %Delete% will remove it from the popup menus used to select variables (which otherwise includes all variables with values and all variables used in any macro).

I’m seeing a different behavior here:

  • Setting variable to %Delete% (+ run macro): Removes the variable immediately from the pref pane and the popup

  • Setting variable to empty (+ run macro): Leaves the variable in the pref pane and the popup unless I…

  • rename the variable in the Set Variable action (+ run macro) --> it gets renamed in pref pane and popup, and has missing value

  • remove the Set Variable action (+ run macro) --> it disappears from pref pane and popup

That’s what I’m seeing, too.

%Delete% removes variable from both the preference pane and the popup list.

Empty leaves it in both, but it of course has no value in it.

What am I missing here?

Yes, it stays, but only as long as I don’t remove the Set Variable action. (A variable with a “real” value stays also after removing the Set Variable action.)

Sorry, you’re quite right, I changed it so they were consistent, so:

Setting a variable to empty will leave the variable displaying in both the Variables and the popup menu list.

Setting a variable tho %Delete% will hide the variable in both the Variables and the popup menu list.

If you delete all actions referencing a variable, and if the variable is empty, it will also stop appearing in both the Variables and the popup menu list.

Ah. That makes perfect sense.