I’m clearing out some of my old code and found this little gem. mdfind2 is a replacement for Apple’s mdfind command line tool. This version adds one feature that mdfind doesn’t have, you can specify the –xml switch on the command-line to output the results (including full attribute values) in XML.
Here’s an example of output (or just one file, normally the output is a lot longer):
<spotlight>
<query>kMDItemTextContent == "xyzzy"</query>
<results>
<item>
<name>NSString_PathExtensions.h</name>
<link>file://localhost/Volumes/Shared/Users/Shared/Developer/Products/Debug/ToxicFoundation.framework/Versions/A/Headers/NSString_PathExtensions.h</link>
<attributes>
<attribute key="kMDItemFSOwnerUserID">501</attribute>
<attribute key="kMDItemFSOwnerGroupID">501</attribute>
<attribute key="kMDItemFSTypeCode">0</attribute>
<attribute key="kMDItemFSIsExtensionHidden">0</attribute>
<attribute key="kMDItemID">322662</attribute>
<attribute key="kMDItemFSSize">427</attribute>
<attribute key="kMDItemFSCreationDate">2005-12-19 18:57:40 -0500</attribute>
<attribute key="kMDItemFSName">NSString_PathExtensions.h</attribute>
<attribute key="kMDItemFSContentChangeDate">2005-12-19 18:57:40 -0500</attribute>
<attribute key="kMDItemFSCreatorCode">0</attribute>
<attribute key="kMDItemFSLabel">0</attribute>
<attribute key="kMDItemFSInvisible">0</attribute>
<attribute key="kMDItemFSNodeCount">0</attribute>
<attribute key="kMDItemAttributeChangeDate">2005-12-21 11:36:14 -0500</attribute>
<attribute key="kMDItemFSFinderFlags">0</attribute>
<attribute key="kMDItemUsedDates">2005-12-19 18:57:40 -0500</attribute>
<attribute key="kMDItemLastUsedDate">2005-12-19 18:57:40 -0500</attribute>
<attribute key="kMDItemKind">C Header Source File</attribute>
<attribute key="kMDItemDisplayName">NSString_PathExtensions.h</attribute>
<attribute key="kMDItemContentType">public.c-header</attribute>
<attribute key="kMDItemContentTypeTree">public.c-header public.source-code public.plain-text public.text public.data public.item com.apple.cocoa.path com.apple.cocoa.string public.content</attribute>
<attribute key="kMDItemContentCreationDate">2005-12-19 18:57:40 -0500</attribute>
<attribute key="kMDItemContentModificationDate">2005-12-19 18:57:40 -0500</attribute>
</attributes>
</item>
</results>
</spotlight>
Source here: http://toxic-public.googlecode.com/svn/tags/BlogTag_20070927_729/Spotlight/mdfind2/ Binary here: http://toxic-public.googlecode.com/svn/tags/BlogTag_20070927_729/Spotlight/mdfind2/Projects/Output/mdfind2.zip
- Update: Just found an XSLT file that can used to transform the output of mdfind2 to an atom file: http://toxic-public.googlecode.com/svn/tags/BlogTag_20070927_729/Projects/Spotlight/mdfind2/SpotlightToAtom.xsl - and now of course I’ll need to work out how to get this working in NetNewsWire
Update: Well that didn’t take long! I can now perform spotlight queries in NetNewsWire:
- Download mdfind2 and the SpotlightToAtom.xsl files.
- Create a shell script with containing:
Example:
#!/bin/sh
~/Products/Debug/mdfind2 --xml $* | xsltproc "$HOME/Library/Application Support/mdfind2/SpotlightToAtom.xsl" -
Fix the paths to mdfind2 and SpotlightToAtom.xsl to suit your environment. 3. Create a new script special subscription in NetNewsWire and configure it to point to the script you just created. Set the parameters of the script to the Spotlight query you want executed…SpotlightNNWSpecialSubscription.png 4. Execute the query (or refresh the feed) and NetNewsWire should display the results of the query:
Add New Comment
Viewing 3 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment