Quickly add Spotlight Comments using Automator

Saturday, June 26, 2010 at 10:04 pm

One of the more remarkable features of Mac OS X is the search function, referred to as Spotlight. It’s the little magnifying glass icon in the uppermost right-hand corner of the screen. You click there to begin searching for things: anything. This search is powerful: it will even index and recall specific text inside documents. You know there’s a PDF invoice, somewhere, on the system, let’s say, but all you know is the dollar amount on the bottom line. Put those digits into Spotlight and chances are, it’s going to turn up your hiding document.

Further, all items in the Finder can have “Spotlight Comments” added to them: files, folders, apps, aliases. And of course, when it comes time to search, one thing that Spotlight goes to work, looking for, are these Spotlight Comments. A simple way to add Spotlight comments to an item would be to right-click (control-click) it and select “Get Info”. A panel will fly out. There are many parameters that can be reviewed there and there are small gray disclosure triangles that allow you to turn up/down particular groups of parameters, if you’d like. The uppermost region is important. This is where you can enter your own Spotlight Comments. This makes finding your file/folder much easier later on.
Spotlight Comments area (empty)
However, what if you have 1,156 new pictures from a recent trip and all of them could reasonably take on the same set of Spotlight comments. You probably would not want to add the comments one-at-a-time. I sure wouldn’t! And if that were the only way to do it, it would be a deal-breaker for most folks. Luckily though, you have them option to add Spotlight Comments to a group of items, all at once, using the Automator application.

When you launch Automator it starts with an empty “workflow” that looks something like this:
Workflow New

There are a few ways to get things going: If you know of particular phrases that are part of the Action that you want to employ, you could start typing them in the area where it says, “Name.” Alternatively, you could immediate thin things out a bit if you know that the Action in question will be used for “Fonts” or “Mail” or “Files and Folders”, for example. The Automator Workflow that we’re going to build applies specifically to “Files and Folders” so if we click that the list of Actions will be thinned down to reveal acts that are only applicable to Files and Folders:
Workflow Files Folders Finder
At this point, it’s probably worth mentioning, that you could use both search techniques mentioned above: you could first click on the proper category of Actions; then begin typing more information into the “Name” area.

The two actions we’re looking for should now be visible in your Actions list. They are “Get Selected Finder Items” and “Set Spotlight Comments for Finder Items”. You can click the first one of these, hold ⌘ (the Command or Apple key), and then click on the other Action.
Workflow Actions Selected
With both of them highlighted, drag them both to the right. Your Automator panel hopefully now looks like this:
Workflow Done
The “Get Selected Finder Items” action should be on top. If, for some reason, it’s not – simply drag it above the other Action and you’ll be ready to save. Go to File > Save as and your options will look like this:
Workflow Save As
The File Format needs to be “Workflow” so change this if need be. I called my workflow, “Add Spotlight Comments.” The save location is very particular. Save this workflow into the Folder:
Users : your_username : Library : Workflows : Applications : Finder :
(If that complete path doesn’t exist, use the Finder to manually create it.) Save your workflow here.

You’re done. All you have to do is call the Workflow up. Go the Finder and right-click on a file or folder. At the bottom of the resulting fly-out panel you should see an option that says “More”. Hover over that and you will see “Automator”. Hover over that and you should “Add Spotlight Comments” – if you named your workflow as I named mine – otherwise, the workflow will be called whatever you named it. Click it.
Window Right-Click

This final dialog box, that flies out, will be where you type your comments. If you wan to add onto any existing comments, leave the box checked for: “Append to existing comments”. If you want to overwrite any existing comments then un-check this box. That’s it.
Workflow Comment here box
If you now go to the Finder and invoke the “Info. Panel” you will see that the Spotlight Comments area is now filled with whatever comments you just added. Further, if you do a Spotlight search for any of the respective comments you should see the appropriate files show up pretty high on the “found” list.

The greatest thing about this is that process is that it applies to a multi-file selection. So now if you go to that folder full of recent pictures, select them ALL, right-click – Add Spotlight Comments – and wait. In only a few seconds, all 1,156 of your pictures will inherit your custom Spotlight comments. And they will found so much quicker, in 4 years, when you can’t remember what you called them or where you put them.

I hope you find this Mac tip handy!

Categories: Mac

14 Comments on “Quickly add Spotlight Comments using Automator”

  1. Hi. This is killer, but I just upgraded to Lion and can’t get this workflow to appear after right clicking. Any suggestions?

  2. Hi Jamie, I’m not sure what the issue would be. Personally, I consider my systems to be “workstations” that I need to be solid and reliable. As such, my upgrade timeline is pretty conservative. Point is: I’m still on Leopard, 10.5.8 on the laptop I’m using right now AND on my Mac Pro too. So it might be a while before I can test this out on Lion.

    It’s not quite as elegant, but you could simply make a “droplet” or an application from the Workflow first. Then you drop all the files in question onto the “application”. Problem is: you’d need to adjust it for EVERY set of Spotlight Comments you want to assign. Not quite as smooth as just typing in the comments on-the-fly, per incident.

    I’ll try to let you know more when I get to Lion.

  3. what about snow leopard?
    I can’t see the script on the finder pop up 🙁
    there is no a “more” option but a “services” option.

    any idea?

  4. Gustavo,

    You’re in luck. I just figured out how to make this work in Snow Leopard. Yes, it is a slightly different technique. But only slightly!

    When you start up Automator, or a new Automator document you select from a group of templates. In this instance you want to start a new SERVICE.

    At the top, a small asks what kind of input you’re hoping to feed into the service. You want to select, “files or folders” in “Finder”.

    You’re almost ready to go. Drag in the “Set Spotlight Comments for Finder Items”. One important step. When the action is in place, click the “Options” button. Then click the check-box for “Show this Action when the workflow runs”. (If you don’t do this, nothing will happen when you run the action.)

    Save the Automator file and that should be it. Once you right-click on a Finder item now, you should now see the new Action at the bottom of the contextual menu.

    PS: Jamie, don’t know if this will work on Lion. If you read this, will you try it and report back. Maybe I’ll do a proper blog addendum to address the newer versions of the Os: Snow Leopard + Lion.

    Thanks for checking the blog out. Hope this little tweak helps get you guys rolling again!

  5. Hey thanks!
    I figured out the “new Services” part yesterday but I didn’t figured the ““Show this Action when the workflow runs”” part.

    Now it woks but, when I use the “append” option, I got duplicated comments. 🙁

  6. …well that’s what “append” does. It adds to current comments. If you have Spotlight comments already, and want to add more comments, while keeping what’s there — you use “Append to existing comments”.

    If you don’t need to ADD comments you turn this off and the “new” comments will simply overwrite anything & everything that was already there.

    I touched on this near the bottom of the blog post.

    HINT: If you need to completely clear all comments then turn off “Append to existing comments” then leave the comments area blank and commit to it. This will, essentially, delete all Spotlight comments from the files/folders in question and you’ll be left with NO comments.

    Hope this helps.

  7. Oh,
    I understand what “append” option means, I’m talking about real duplicated comments, actually “doubled” with an “return” character in the middle, for example adding the comment: “B” to an archive that already has the comment “A” with the append option turned on will produce this result:

    A
    B
    B <-duplicated!

    Is like it writes the comment then it sends a "return" then writes the comment again, you can see a slight delay between the firs and the second ocurence
    if the Info window for that file is opened.

    I just tested this in LION and it happens something similar but duplicated are placed on the same line, without the "return"

    For example, adding the comment "123" to a file that has no spotlight comments on it with append mode on, will results on this comment: "123123".

    I have two machines with Snow Leopard and is the same problem in both: 10.6.5 and 10.6.8,
    Lion is 10.7 (upgrading right now)

    I replaced the "Set Spotlight Comments for Finder Items" with the "Run Apple Script" with an apple script I found on the web and it works perfect, with the exception of files laying on desktop. I can share here the script if you want.

    Best

  8. Kevin – thanks for the tip. I couldn’t get my service to work – no dialog box was appearing but you have juts explained why.

    Gustavo – I had the same problem and sent tweet to Ben Waldie who writes books on Automator and he told me to remove “Get Selected Finder Items” option from the workflow as items dropped on the app are input automatically. Send a tweet to @applescriptguru and he’ll reply – very helpful guy. I had this workflow on my desktop and was dragging files to it but have now created a service instead so I only have to right-click the selected file(s). Interesting interview on Automator with Ben on Mac Powers Users podcast, episode 70 from 23/01/12.

  9. Sorry for my absence from the conversation. Been quite busy here. But thanks for the additional tips, Alison.

    Gustavo, does Alison’s tip rectify the oddness you’re seeing at all?

  10. Screensnap & with spotlight comments (using text from copy buffer)

    Hi
    It would be totally awesome to create screen snapshots with pertinent text in the spotlight comments.
    I use the screen capture feature all the time when I am researching. Whenever I see a web page with some info i need, I hilight the text on the page that is most relevant and then take a screen capture of that page. Then I can very easily visually find the thing again in a year by looking at the history of my snapshots. Works really well for me, but…
    I want to go one step better – I want the text that I hilight on the page to be searchable later by spotlight.
    So I want to make an automator script that will ad that text into the spotlight comments

    So this would be my workflow:
    1) go to a web page I like
    2) hilight the most relevant text and copy it
    3) run automator script which does the following:
    – makes screen capture of the web page
    – pastes the text (which is already in the copy buffer) into the spotlight comments for that screen capture image.

    Some thoughts;
    This has to work on the “last captured image”, so maybe I could make the screen snapshot save in a temp folder, which has “folder action”. That “folder action” adds that spotlight text (from the copy buffer), then it moves the image file to the desktop.

    It would be totally awesome to create screen snapshots with pertinent text in the spotlight comments.

    Does anyone know a way to achieve this using automator (or a terminal script)?

    I know I could already just go to the finder, find the image file, command+i and paste the text into the spotlight comments. But that is actually too cumbersome for my workflow. I make these snapshots constantly when I am researching. It needs to be done with one hotkey without interrupting my web browsing.
    That would be so awesome.

  11. @MarkV,

    I hear you. I think lots of people use screenshots as a quick way to document their work. And I think what you’re looking to do is likely possible. You way want to poke around at macscripters.net to see if there is already a solution in place.

    However, I’m going to recommend an alternative workflow. You may have unforeseen objections to this suggestion but here it is: save the web pages as Web Archives or PDFs.

    With this tactic:

    1.) The default name of the document you create will already care the name of the webpage, vs. ending up with a ton of files called “Screenshot….. ”

    2.) There is no need to paste text into spotlight comments because spotlight will automatically EVERY bit of text in the respective document.

    3.) In Icon view you still end up with a thumbnail visually representing your document.

    4.) The whole process can still be automated—then married to a “hot-key”.

    Again, you may have unknown aversions to this strategy. But it might work better for your needs. I see it as a quicker best-of-both-worlds scenario. The result is a searchable document AND a visibly identifiable document, all at once.

  12. .

    Here’s a modification to the Spotlight Comment Automator Action

    “Edit” what is already there – dig ?

    Not able to find a ‘Script/Action’ to do that

    Have a large number of Tovaly File Archives (great little ‘Finder Cataloging’ Program – if don’t know it, worth a look-see, it makes ‘semi-alias’ type ‘copies’ – of zero actual size – for Files stored on discs/etc)

    One of the ‘Options’ in running Tovaly is creating an Entry in Spotlight Comments to give the Size of Original File

    Comes out as … (Original file size: 1234567)

    Want to keep the Info about the File Size – that number (parenthesis are optional)

    Just want to remove the phrase – Original file size:

    If a way to do that, or a ‘Script/Automator Action’ already exist ?

    I haven’t found it anywhere, not able to figure it out myself , and don’t want to try to ‘hack the terminal’ (ha ha)

    .

    Plus – And/Or …

    Way to ‘hack’ Tovaly so … “Original file size: ”

    Not be entered in the first place, just the ‘number’ – dig that too ? (smile)

    .

    TIA for any ‘help’ on this

    BC

    .

  13. @BC Kelly,

    See if the AppleScript code posted here helps out. Definitely run it on TEST files before you commit to running it on a large batch of “real” files. In theory you’d select your items in the Finder. Then run the script. It will ask you for the text you want to replace, then the text you want to substitute into the Comments. Done.

    If however, the specific comments you are hoping to replace are going to be absolutely identical every time, let me know. I can show you how to tweak this script so it doesn’t ask you for anything. The “find and replace” parameters can be locked into the script so it doesn’t prompt you for input.

  14. Have an Automator for bulk commenting.

    However, use Commenteer* now. Great app. Use it especially to tag my thousand or so iOS apps.

    * http://itunes.apple.com/us/app/commenteer/id439790859?mt=12

Post a Comment