APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2005/05/10 Smart Folders (Mac OS X)

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"
"http://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.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Smart Folders (Mac OS X)




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





Writing in C or C++ is like running a chain saw with all the safety guards removed. (Bob Gray)

Securing a computer system has traditionally been a battle of wits: the penetrator tries to find the holes, and the designer tries to close them. (Gosser)












This post tagged: