Macro to add tags

Hello all,

Looking for a macro which would both create a tag named after a folder, and then apply tag to all files in that folder.


Folder is Draft
Tag created is Draft

Files in Draft folder get assigned Draft tag.

Could also be two separate macros if need be. any help greatly appreciated

1 Like

There will be several ways of doing this.

Assuming you have the Folder with the Files you want to tag open in the Finder, a simple method to get the enclosing Folder name is to use the open Finder Window Name (which will be the same as the Folder name).

The Keyboard Maestro Token %WindowName%1% is the name of the front open Window and is used as the Tag name in the last Action of the Macro.

Like I said, this Example requires you to have the Folder open and displayed as the frontmost window, for it to work. If you wanted to do it the other way around (i.e. select the closed Folder in the Finder and Tag the files inside that closed Folder) that would still be possible but would mean getting the Folder name a different way.

EXAMPLE Tag All Files in Folder with Folder Name.kmmacros (3.8 KB)

Screen Recording 2022-07-23 at 12.42.42-Animated GIF

EDIT: After uploading the first version of this Macro I realised that as it "selects all" if you were actually not in the Folder you thought you were in, you could accidentally Tag a lot of files and folders with the wrong Tag... So, I added in an Alert Action just so you can preview what the Tag will be before going ahead or cancelling.


As chance would have it I already had a macro that removed all the tags in the files in selected folders, so I've modified it as follows:

Select the folders you want processed in Finder (it doesn't matter if you select files by accident as the macro will only process folders). Trigger the macro and then, for each folder that you've selected the macro will display the tag that will be applied to each file in that folder and give you the opportunity to change it if you wish.

As usual for any macro given to you by someone you should test it on files that are copies/unimportant to ensure it does as you wish. I have tested it myself and it seems to be ok.

The macro has been uploaded in a disabled state and you'll need to set up a hot key trigger that suits you.

P - Set Tags in Finder Selection.kmmacros (8.8 KB)

Click to see macro


Wow. Lots of clever stuff going on here that I will borrow :grinning:

1 Like

Be my guest :+1:

Thank you so much! greatly appreciated!