TAG OPEN DOCUMENT(S) - v1.3.kmmacros (49.3 KB)
(uploaded in disabled state)
So, it turns out that even if a document is open, it can be tagged in MacOS. This makes me happy, and it can make our lives a little bit easier.
Sometimes when I am working with an open document or a batch of open documents - usually a PDF or Word or TextEdit document or documents - I want to quickly tag it/them for later quick retrieval via Spotlight. But to do this, I would typically leave the work I am doing in an open document, locate the document in Finder, and tag the item there, then go back to the open document. That's a pain. For multiple open documents, often from different file locations, it becomes maddeningly tedious, when all I want to do is quickly tag my open document or documents right when it occurs to me to do so, and then get right back to work.
This UPDATED macro leverages scripts by @ccstone and @Nige_S to retrieve the filepath(s) of almost any kind of open file(s)/document(s), then it prompts the user for comma-separated tags, then it tags the open document or all open documents in a given app, accordingly, without having to interact with Finder. I have tested this with Preview, Word, Excel, Powerpoint, and TextEdit. It works even with unsaved, in-progress Office documents (although the documents must have been saved at least once so that they have a file location). It should work with most any item that has a file location and can be tagged in MacOS.
One aspect of the UPDATED macro that may seem tedious is that for file types other than Preview, TextEdit, Word, Powerpoint, and Excel, and probably other apps, if you choose to tag all your open documents (in a given app), the macro must bring each open document to the front briefly in order to get the filepath using @ccstone's most useful script. I personally can live with this, because the overall time save is worth it. (See further discussion below regarding scripting solutions for different apps.)
This UPDATED macro prompts the user to ADD or REPLACE tags. The macro will throw up a self-dismissing dialog briefly showing you the tags set to the file. Obviously, that element can be omitted if you don't care about that.
What I love about KM is that it so powerfully engages the most laudable utility of the computer, which is to enable human users to quickly and intuitively organize and retrieve information. I offer this macro in that spirit!
Cheers!