Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Automate Spotlight comment tags via AppleScript System 10.4
Tiger only hintKirk McElhearn recently blogged about using Spotlight to find Smart Folders. His idea, which is a good one, was to use the Comments field to add a unique identifier to saved searches -- "RobSearchFolder" or whatever; just make sure it's unique to your saved searches. Then use Spotlight to search for that unique string, and you'll see all your saved searches in one spot, regardless of where you might have saved them (you can get the same effect with a folder in the Sidebar, but really, that's not the point of this hint).

Kirk's entry got me to thinking about better ways to use the comment field in Spotlight, so I talked Doug Adams (of Doug's AppleScripts for iTunes fame) into writing an AppleScript for me. The essence of the AppleScript is that it will automatically tag any item added to a designated folder with a Spotlight comment of your choice. If the item already has Spotlight comments, the script will append them, so you won't lose any existing comments. This can help automate the process of making some of your content very easy to locate with Spotlight. Here are a few ways you might use this script:
  • As originally envisioned, automatically tag any Finder Smart Folders (i.e. saved searches) with a unique identifier.
  • Tag items you place in your "Client XYZ in Process" folder with a unique client identifier. When the items are later permanently filed, you could find them quickly by using Spotlight on that identifier, regardless of where they eventually got filed.
  • Tag your Downloads (or Games or whatever) folder with a "HaveNotTestedYet" flag. You can then quickly find which ones you haven't run, even if the programs get moved at a later date.
In short, the script will let you tag anything in any folder, easily and automatically. Read on for the script and exactly how to put it to use...

First, open Script Editor in /Applications/AppleScript, and paste in the Spotlight Comments script. Modify the flag line, replacing MySpotlightComment with the unique value you'd like to use. Make sure it's something that Spotlight won't find in any other files. Now save the script in your user's Library/Scripts/Folder Action Scripts folder -- this is key, for the script won't work unless it's saved here. You may have to create the Folder Action Scripts folder if it doesn't yet exist. Give the script a meaningful name for the role it will be playing. "TagSavedSearches," for example, if you're using it for your Saved Searches folder.

Next, you need to make sure you've got Folder Actions enabled. Select any folder, control-click on it, and choose Enable Folder Actions from the pop-up menu. If you want to use this hint for the Finder's Smart Folders, first make sure you've created a few saved searches (so the following folder will already exist). Then navigate to your user's Library/Saved Searches folder, and control-click on it. Select Attach a Folder Action from the pop-up menu, then navigate to the Folder Action Scripts folder in which you saved the script. Click on the script's name, then click Choose. That's it, you're done.

From now on, any time you save a Finder search, it will automatically be tagged with the string you entered into the script (note that existing saved searches are not tagged; you'll have to add the tag yourself, or delete and recreate the searches). You'll see a dialog pop-up, letting you know the search has been tagged. You can disable this by commenting out (add -- at the front) the line that begins display dialog....

To use the script on other folders, just duplicate it, rename it, then edit it to change the unique comment value. Control-click on the folder you wish to 'tag,' and then attach the newly-duplicated script.

Thanks to both Kirk for the idea and to Doug for all the hard work -- I've already got this script working on my Saved Searches folder, along with a couple job-related folders. It's a big timesaver...
    •    
  • Currently 2.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[27,064 views]  

10.4: Automate Spotlight comment tags via AppleScript | 13 comments | Create New Account
Click here to return to the '10.4: Automate Spotlight comment tags via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Automate Spotlight comment tags via AppleScript
Authored by: Arlo on Jun 14, '05 10:49:04AM
FYI, this Automator workflow does the same thing, and is a bit more convenient, as you can enter the comment on the fly without modifying the code: http://www.automatorworld.com/2005/05/03/add-spotlight-comments/

The workflow can be saved as a folder action the same as this hint.

---
www.automatorworld.com
"Better Living Through Macintosh Scripting"

[ Reply to This | # ]

10.4: Automate Spotlight comment tags via AppleScript
Authored by: leary on Jun 14, '05 11:45:07AM

Actually, what I love about this is that it makes things completely automatic. I've attached this to a project folder with the name of the project as the tag. Now every file created in this folder is automatically tagged with the project name. I've deleted the line in the script that launches a confirmation dialog, so now the process is completely seamless.

Thanks for this!



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: abobrow on Jun 14, '05 01:03:47PM

Well this seems silly to me. You're creating a spotlight comment to make files easier to find, but in order to get that comment, the files have to be placed in a specific folder in the first place. Doesn't being in the same folder make them easy enough to find without the comment?



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: adrianm on Jun 14, '05 02:03:19PM

LOL



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: abobrow on Jun 14, '05 03:56:32PM

It's like: "Hey everyone, I've created this magical Saved Search that automatically shows me all the files in a folder. Oh wait, opening the folder does the same thing..."



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: mark12b on Jun 14, '05 07:12:13PM

Next we will see a systematic tagging method that simulates hierarchical folders.



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: robg on Jun 22, '05 01:03:05AM

Clearly none of you work with a temporary folder -- I use them all the time, and this script is perfect. Everything that flows through the temporary folder gets tagged, and when it's later permanently filed, Spotlight already knows about it.

That's the point of this hint...

-rob.



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: sjk on Jun 23, '05 08:11:38PM

Thanks for clarifying that, Rob.



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: robg on Jun 22, '05 01:03:05AM

Clearly none of you work with a temporary folder -- I use them all the time, and this script is perfect. Everything that flows through the temporary folder gets tagged, and when it's later permanently filed, Spotlight already knows about it.

That's the point of this hint...

-rob.



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: pub3abn on Jun 14, '05 03:15:05PM

Perhaps the folder that triggers is a subfolder of the user's drop box. The user then moves the files to various other folders, where the files each retain the appropriate comments.



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: da5idonimac on Jun 14, '05 03:21:27PM

i use this script to tag the files in a certain mailbox-folder. mail.app pushes the mails directly into the mailbox and now they get spotlight-tagged automatically.



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: ncc59 on Jun 14, '05 04:01:29PM

You did not get the point.
With this script you're able to use BOTH folders and spotlight search (depending on your mood... or depending on what is more convinient and time saving for a specific searcg)
and you keep the best of both world, being able to maintain a hierarchy in your savedsearch which, otherwise, are kept separate. Actually, with this script you can "mark" your file to belong to different savedsearches, which is a new way to use Spotlight (nested virtual folders !). I've already seen this idea in another discussion thread (can't remember where, sorry) but it's actually working now...

Brilliant idea IMHO and very nice script.



[ Reply to This | # ]
10.4: Automate Spotlight comment tags via AppleScript
Authored by: popdanne@mac.com on Jun 15, '05 07:15:17AM

Isn't there a way to use boolean in "types" to like cat(-type=folder) date:today
because im trying to make a smartsearch that collects all resent changed and created files exept folders and applications. is that posible?



[ Reply to This | # ]