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.
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 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)
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.
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
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.
==CURRENT VERSION: v3.1.1 Monday, May 08, 2023==
Added a pause until system clipboard changes after the shell script to read the plist file to ensure the XML is on the clipboard before proceeding.
This should prevent false positives.
Version History (click to expand/collapse)
v3.1.0 Wednesday, February 22, 2023
Switched to using a named clipboard to avoid interference with other macros that monitor my system clipboard to automatically reformat certain strings.
v3.0.0 Saturday, February 11, 2023
Now uses plutil command line to read the duplicated plist file.
BBEdit (and other text editors) are no longer a requirement.
2.0.0 (Friday, February 10, 2023)
Now uses AppleScript to open the copied plist file in the background
v1.1.0 Wednesday, March 23, 2022
Added some actions to show progress percentage in progess bar
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
Screen recording (click to expand/collapse)
22)Files- Search KM Plist File for Embedded File(s) and Tag.kmmacros (51 KB)