Find Which Files Are Used in Your Macros and Tag Them Accordingly

Howdy folks, recently I was (apparently) confused about how to search for files that are embedded in macros. For whatever reason, when I would search the Editor for a file's name, it would not always give me any results, even if that file was indeed embedded in a macro. So I set out to build a macro that would search my macro database to see if a particular file (or batch of files) were embedded in a macro's actions.

After completely rebuilding the macro twice, I have what I believe to be a working, stable version that is quite efficient. I was able to scan over 3,000 files in about 3 minutes!

RELEASE NOTES, INSTRUCTIONS AND DISCLAIMER

Purpose of this macro (click to expand/collapse)

This macro is designed to search the Keyboard Maestro master plist file (by creating a duplicate, no action is taken on the actual file itself to avoid any damage to your macro database) to find if the file(s) you selected are embedded in a macro and tag them with a tag of your choice, or remove previously added tags to files that are no longer in the database.

It can be helpful to be able to quickly check which files are currently in use in your macros before making changes to them.

How this macro works (click to expand/collapse)

The KM master plist file is duplicated to a temporary folder in /var/tmp/.
That file is opened in BBEdit, the entire contents is then selected and copied to the system clipboard, the file is closed and the temp folder and file are trashed.
The clipboard is then searched for each file name to see if it is in the KM plist file contents.
If it is, it is tagged with Keyboard Maestro and it's path is appended to a variable.
If it is not, it is not tagged, but it's path is appended to a different variable.
If it was previously tagged indicating it was once in the KM plist file but is no longer there, the tag is removed and it's path is appended to another variable.
Files that are not in the plist file and are not tagged are not modified in any way, and their filepath is appended to another variable.
After the clipboard is searched for each file, a display text window appears showing which file(s) were tagged, which ones weren't, which ones had tags removed, which ones didn't need any action taken, and showing that the temp folder was trashed.

How to configure this macro (click to expand/collapse)

You must have BBEdit to use this macro, or another text editor capable of opening plist files.
If you do not use BBEdit, you will have to modify the portions of the macro that interact with BBEdit to work with your preferred text editor (purple-colored actions).

You may need to adjust the path of the temporary folder depending on how your system is configured.
I chose /var/tmp/ because it's a safe place where I don't have to worry about the folder/file being synced to any cloud services.

Set the purple-colored variables to indicate what tag you would like to add to the files (replace Keyboard Maestro with the name of your tag or leave as is), as well as whether you want to trash the unused files or not (using Yes or No as the value).

How to use this macro (click to expand/collapse)

Select the file(s) you would like to search for and trigger the macro.
You don't have to worry about having directories in your selection as those are skipped automatically.
That's it!

Disclaimer (click to expand/collapse)

TL;DR: I built it and it works for me. You can share/modify it how you want. But don't blame me if it doesn’t work for you :laughing:

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

-Chris

CURRENT VERSION: 1.1.0 (Wednesday, March 23, 2022)

v1.1.0 Wednesday, March 23, 2022
Added some actions to show progress percentage in progess bar

Version History (click to expand/collapse)

v1.0.2 Saturday, March 05, 2022
Changed from AppleScript to native KM action to close BBEdit window

v1.0.1 Thursday, February 17, 2022
Adjusted the search portion to include the file path to rule out duplicate files (in different directories) from being improperly tagged.

v1.0.0 Wednesday, February 16, 2022
Initial macro

MACRO INFORMATION

Screen recording (click to expand/collapse)

Search KM plist file for embedded files and tag

Macro screenshot (click to expand/collapse)

26)[AS-F] Search KM Plist File for Embedded File(s) and Tag.kmmacros (62 KB)

1 Like

Version 1.0.1 is now up with only minor changes. See post 1 for details.

Version 1.0.2 is up with only one minor change. See post 1 for more details.

Wednesday, March 23, 2022: Version 1.1.0 is up with minor changes to the progress bar. See post 1 for details.