Opening a file with a specific tag

Hi there. I’m trying to set up a macro that is a “start of the day, launch all my applications, a couple of current documents and open a new project from a template file” thing. I work off of a specific template file in Digital Performer for a few weeks at a time, then move onto a different one. A new template file gets created for each project, and they’re in different folders, so it’s not pulling from exactly the same location each time.

It seems to me that a way to go about it would be to have my current project template tagged with a “CurrentTemplate” tag, one that gets added when I start a project and removed at the end so there’s only one file tagged like that on my drive. Is there a way to have KM search for a specific tag and open that file? It seems like something possible, but I haven’t figured out how to do it yet.


Are they all in the same folder? If so, you can easily search a folder using the Folder Contents collection.

If not, you would have to search your whole disk, which I think can be done using the mdfind unix tool, something like:

mdfind 'kMDItemUserTags == CurrentTemplate'

Otherwise, you could potentially just select the new template file, and run a Keyboard Maestro macro that saved the Finder selection path in a variable, and use that variable in your script. Your script could deal with the variable being empty (if it had been erroneously deleted for example) by prompting you for the file.


Hi Peter, thanks for getting back to me. I have them on the same drive, and as part of my “Current Projects” folder, but each project has it’s own hierarchical folder system, so the template for each project is in its own folder. Sort of like this:

Current Projects folder
— Project 1 Folder
----- Documentation folder
----- Sequences
----- Template
------- Template 1
----- Deliverables
— Project 2 Folder
----- Documentation folder
----- Sequences
----- Template
------- Template 2
----- Deliverables

I think the best option might just be the third one you mentioned, saving the Finder Selection path as a variable and recalling it from a macro. That way it accounts for them being in separate folders, but doesn’t do a search on the whole system. Does that sound right?

Thanks for your help!

Yes, just select the template file, or if your naming system is sufficiently consistent, you may be able to select the project file, and add the /Template/TemplateFile to the path.

No need to search your entire hard drive.
The mdfind command can be restricted to search only in a certain folder.

This macro should get you started.
The shell script is:
mdfind -onlyin "$KMVAR_Local__ParentFolder" "kMDItemUserTags=$KMVAR_Local__Tag"

You will need to CHANGE the first Action to be the full path to your top level Projects folder.

Note that this will return a list of ALL FILES with the specified tag.
So you will need to be sure to remove the tag from all other files, or add KM Actions to select the temple file you want.


Example Output:


MACRO:   Get List of Files with Specific Tag [Example]

~~~ VER: 1.0    2018-02-09 ~~~


Get List of Files with Specific Tag [Example].kmmacros (3.9 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.



That’s awesome, I’ll give it a try. Thanks!

Hey JMichaelTX, I’ve had a chance to give it a shot, and it looks like that’ll do the trick. I’ve replaced the last Display Text action and with an action to Open %Variable%Local__FileList%, so far it seems to be working.

Thanks for the help!

1 Like