<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zach Archer Blog &#187; Spotlight</title>
	<atom:link href="http://blog.zacharcher.com/tag/spotlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zacharcher.com</link>
	<description>This blog is GO!</description>
	<lastBuildDate>Fri, 09 Jul 2010 23:02:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A Replacement for Spotlight</title>
		<link>http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/</link>
		<comments>http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 01:53:55 +0000</pubDate>
		<dc:creator>Zach</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Spotlight]]></category>

		<guid isPermaLink="false">http://blog.zacharcher.com/?p=27</guid>
		<description><![CDATA[Spotlight has a glut of nice features, but it still doesn't satisfy me. I have nearly 2 million files on my hard drive. Depending on what I'm working on (and my caffeine-to-blood ratio), hundreds of files may be updated every minute. Then Spotlight tries to index the drive at inopportune moments, then Ableton Live can't [...]]]></description>
			<content:encoded><![CDATA[<p>Spotlight has a glut of nice features, but it still doesn't satisfy me. I have nearly 2 million files on my hard drive. Depending on what I'm working on (and my caffeine-to-blood ratio), hundreds of files may be updated every minute. Then Spotlight tries to index the drive at inopportune moments, then Ableton Live can't access files because the drive is busy, and the music grinds to a halt, and .... well, I had to take Spotlight behind the shed, and put it down.</p>
<p>There are <a href="http://www.macosxhints.com/article.php?story=20071102215912892">many</a> <a href="http://aplawrence.com/foo-mac/remove-spotlight.html">ways</a> <a href="http://www.tuaw.com/2008/09/23/terminal-tips-disable-spotlight-in-menu-bar/">to</a> <a href="http://pseudogreen.org/blog/disable_spotlight_in_leopard.html">disable</a> Spotlight. I don't remember which combination worked for me, but the end result is that <code>mdutil</code> doesn't  run on this machine anymore, and my menu bar is devoid of a Spotlight icon. (Also I <a href="http://forums.macosxhints.com/showpost.php?p=485190&amp;postcount=23">disabled Quick Look</a>, since its indexing also caused problems.)</p>
<p>But I still want to search my files. My solution was to create an automated job that runs once a day, and saves the path of every file into a big text document. Then I created a little command-line alias called <code>search</code>, which prints any file paths that match a search term. Here's how to do it:</p>
<p><span id="more-27"></span>First things first... We need a script that will traverse the file system, and save the path of every file into a massive text document. This is pretty easy, the <code>find</code> utility can do the heavy lifting. Here's the script I wrote:</p>
<p><code>#!/bin/bash<br />
rm /Users/chaz/dev/search/tree.txt<br />
find / &amp;gt; /Users/chaz/dev/search/tree.txt</code></p>
<p>I saved this script as <code>/Users/chaz/dev/search/build_tree.sh</code> . Make sure it's executable, then run it:</p>
<p><code>$ chmod a+x build_tree.sh<br />
$ ./build_tree.sh</code></p>
<p>The first time through, the <code>rm</code> command will complain that it has no <code>tree.txt</code> to delete, but that's okay. <code>find</code> will throw some other warnings at you: it can't traverse every directory because it doesn't have permission. Again, that's okay -- I probably won't be hunting for files in such places.</p>
<p>Grab a beverage, this process takes a few minutes. When it's done, you'll have a (rather large) <code>tree.txt</code> file in the directory. How large, exactly?</p>
<p><code>$ wc tree.txt<br />
1719365 5761267 196118611 tree.txt</code></p>
<p>1,719,365 lines, so I just indexed 1,719,365 files. Awesome.</p>
<p>It would be nice if the indexing ran automatically, preferably when I'm asleep. Since <code>cron</code> is being phased out of OS X Leopard, we'll use <code>launchd</code> instead. I created this file, called <code>rebuild_search_tree.plist</code>:</p>
<p><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://ww w.apple.com/DTDs/PropertyList-1.0.dtd"&gt;<br />
&lt;plist version="1.0"&gt;<br />
&lt;dict&gt;<br />
&lt;key&gt;Label&lt;/key&gt;<br />
&lt;string&gt;chaz.search.tree.rebuild&lt;/string&gt;<br />
&lt;key&gt;ProgramArguments&lt;/key&gt;<br />
&lt;array&gt;<br />
&lt;string&gt;/Users/chaz/dev/search/build_tree.sh&lt;/string&gt;<br />
&lt;string&gt;daily&lt;/string&gt;<br />
&lt;/array&gt;<br />
&lt;key&gt;LowPriorityIO&lt;/key&gt;<br />
&lt;true/&gt;<br />
&lt;key&gt;Nice&lt;/key&gt;<br />
&lt;integer&gt;1&lt;/integer&gt;<br />
&lt;key&gt;StartCalendarInterval&lt;/key&gt;<br />
&lt;dict&gt;<br />
&lt;key&gt;Hour&lt;/key&gt;<br />
&lt;integer&gt;6&lt;/integer&gt;<br />
&lt;key&gt;Minute&lt;/key&gt;<br />
&lt;integer&gt;15&lt;/integer&gt;<br />
&lt;/dict&gt;<br />
&lt;/dict&gt;<br />
&lt;/plist&gt;</code></p>
<p>Save this into ~/Library/LaunchAgents . You may have to create that directory, and there's an added wrinkle: for both the LaunchAgents directory <em>and</em> the .plist file, the owner has to be <code>root</code>.</p>
<p><code>$ sudo chown -R root ~/Library/LaunchAgents</code></p>
<p>Register this script with <code>launchctl</code>:</p>
<p><code>$ sudo launchctl load -w ~/Library/LaunchAgents/rebuild_search_tree.plist</code></p>
<p>Now this launch agent will run automatically at 6:15 every morning.</p>
<p>Finally, we need a command-line tool to search the tree. I added this line to my <code>.profile</code>:</p>
<p><code>function search() { clear; cat /Users/chaz/dev/search/tree.txt | grep "$@" | more; }</code></p>
<p>And here's how you use it:</p>
<p><code>$ search test<br />
/Applications/Adobe Photoshop CS3/MATLAB/tests/teststats.m<br />
/Applications/Audacity folder/nyquist/test.lsp<br />
/Applications/iTunes.app/Contents/Resources/da.lproj/iTunes Help/gfx/gfx_test.gif<br />
...</code></p>
<p>For each file that matches your query, it displays the full path of the file. This could be made fancier, but for now this is all I need!</p>
<div class='bookmarkify'><a name='bookmarkify'></a><div class='linkbuttons'><a href='http://del.icio.us/post?url=http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/&amp;title=A Replacement for Spotlight' title='Save to del.icio.us' onclick='target="_blank";' rel='nofollow'><img src='http://blog.zacharcher.com/wp-content/plugins/bookmarkify/delicious.png' style='width:16px; height:16px;' alt='[del.icio.us] ' /></a> <a href='http://digg.com/submit?phase=2&amp;url=http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/&amp;title=A Replacement for Spotlight' title='Digg It!' onclick='target="_blank";' rel='nofollow'><img src='http://blog.zacharcher.com/wp-content/plugins/bookmarkify/digg.png' style='width:16px; height:16px;' alt='[Digg] ' /></a> <a href='http://reddit.com/submit?url=http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/&amp;title=A Replacement for Spotlight' title='Reddit' onclick='target="_blank";' rel='nofollow'><img src='http://blog.zacharcher.com/wp-content/plugins/bookmarkify/reddit.png' style='width:16px; height:16px;' alt='[Reddit] ' /></a> <a href='http://twitter.com/home/?status=A Replacement for Spotlight+http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/' title='Save to Twitter' onclick='target="_blank";' rel='nofollow'><img src='http://blog.zacharcher.com/wp-content/plugins/bookmarkify/twitter.png' style='width:16px; height:16px;' alt='[Twitter] ' /></a> <a href='http://www.feedburner.com/fb/a/emailFlare?itemTitle=A Replacement for Spotlight&amp;uri=http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/&amp;loc=en_US' title='Email this to a friend' onclick='target="_blank";' rel='nofollow'><img src='http://blog.zacharcher.com/wp-content/plugins/bookmarkify/email.png' style='width:16px; height:16px;' alt='[Email] ' /></a>  <a title='See more bookmark and sharing options...' href='http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/#bookmarkify' rel='nofollow'><small>More&nbsp;&raquo;</small></a></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.zacharcher.com/2008/10/06/a-replacement-for-spotlight/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
