Mac's Spotlight has the ability to create "Smart Folders". If you click "Save" after doing a Spotlight search, you'll be creating a plist file which by default will be created in ~/Library/Saved Searches. It has a "savedSearch" extension, and contains the necessary information about your search:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CompatibleVersion</key> <integer>0</integer> <key>RawQuery</key> <string>(* = "fogpr1*"wcd || kMDItemTextContent = "fogpr1*"cd) && (kMDItemContentType != com.apple.mail.emlx) && (kMDItemContentType != public.vcard)</string> <key>SearchCriteria</key> <dict> <key>AnyAttributeContains</key> <string>fogpr1</string> <key>CurrentFolderPath</key> <array> <string>/Users/apl</string> </array> <key>FXCriteriaSlices</key> <array> <dict> <key>FXSliceKind</key> <string>Skin</string> <key>Value</key> <string>KI**</string> </dict> <dict> <key>FXSliceKind</key> <string>Slsv</string> <key>Value</key> <string>DA**</string> </dict> </array> <key>FXScope</key> <integer>1396926573</integer> <key>FXScopeArrayOfPaths</key> <array> <string>kMDQueryScopeHome</string> </array> </dict> <key>Version</key> <string>10.4</string> <key>ViewOptions</key> <dict/> </dict> </plist>
This is a "live" folder. If you have it open in Finder, and are creating files in Terminal or anywhere else that will match the criteria, those files will instantly appear in your view.
Note that the conditional string is much more complex than anything you can type in Spotlight itself. You can use boolean logic with the command line "mdfind", and have more control with the View Options of a Spotlight search (especially be selecting "Raw Query"), but you could also manually edit this plist to get exactly what you want.
I haven't yet thought of something I really need Smart Folders for, but the idea does tantalize me. I could set up a smart folder for each customer and thus automatically track any reference in any document, no matter where I created it. I'm sure other uses will come to mind. As GetInfo now includes "SpotLight Comments" where you can add searchable metadata (it's "kMDItemFinderComment" if you are hand-rolling searches), this could get quite interesting. For example, a directory (Folder in Mac-speak) has no particular connection with the type of data you intend to store in it, but you can tag it with anything you like with Spotlight comments.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-03-09 Tony Lawrence
I wanted to learn how to swim, so Google showed me how to turn on the water at the sink and let me splash it around a bit. They then dragged me into a helicopter, flew way out into the ocean and dumped me out. (Tony Lawrence)