Using Hazel after moving ~
When I picked up my ScanSnap a few years ago now, I went as far as I feasibly could at the time with the paperless thing, and I’ve slowly been working my way towards being completely paperless. Right now, any paper bills, receipts, etc. we get are scanned and shredded immediately.
One of the tools that is indispensible to that ability is Hazel by Noodlesoft. The ScanSnap software dumps everything into an "Incoming Scans" folder in ~/Documents. I currently have over 60 rules defined in Hazel for that folder. Hazel can use both the contents and metadata of files to determine actions, and since all my PDFs get passed through OCR on their way in from the scanner, Hazel can sort by company names, account numbers, etc.
Sidebar: Since 2008, up through a week or so ago, my Home directory (~/) lived on a separate volume. The process for this is well documented, so I won't go into it here. Suffice it to say when I bought my Mac Pro I felt the complexity was justified and never had the desire to change it until recently when I decided to rebuild my boot disk from scratch and try to alleivate some of the issues of having 7 years of cruft hanging around in my home directory.
Moving a home directory is generally an easy exercise. We do it all the time at work, moving users to newer hardware. We either use rsync or even Finder to move a home directory, then chmod to reset the permissions accordingly, and move on. With my move it was no different, save for I was a little more selective in what got moved over, since my desire was to shed some of the bloat along the way.
I realized after moving that all my paths in Hazel were hard-coded to my old home directory (/Volumes/Data/Users/peelman/). That meant that while I could change the location of a watched folder quickly and easily, and I could copy in the pre-existing rules from the previous location, all those pre-existing rules were pointed at wrong destination paths, which technically still existed on my system. So all new incoming scans were getting sorted and organized into my old home directory, not the new. That was a wrinkle I didn't forsee.
Hazel doesn't provide a way to bulk edit rules like that, and with good reason. That would be incredibly complex feature, and one of the most unused. The saving grace here is that Hazel does provide the ability to Import and Export Rules. Hazel exports rules as a binary plist file for easy sharing and backing up. But there's no way to do a bulk-edit of a binary plist file; using Apple's PlistEditor isn't possible (Find and Replace doesn't exist). Other GUI tools probably exist for this sort of thing, but after years of messing with packages and plists, I knew a binary plist was more of a pothole than a road block.
Basically the following command uses PlistBuddy (see the man page for more details) to convert the binary Plist that Hazel generates as its .hazelrules file, into a human-readable (somewhat) and editable XML document.
PlistBuddy -x -c Print Incoming\ Scans.hazelrules > Incoming\ Scans.hazelrules.xml
Once the plist is converted to XML, it can be easily opened in any text editor. Find and Replace can then be used to switch any paths over. The more nerdy among us might use SED or Perl or some other complex command line jujitsu to get to the same result, but like I do for most text editing, I used TextMate.
In my case, I basically searced for /Volumes/Data/Users/peelman/ and replaced it with /Users/peelman/.
Once that was done, Hazel will accept the XML plist directly from its Import Rules dialog. There's no need to convert it back to a binary plist (I had originally done just that, before realizing that Hazel was able to accept the XML plists directly).
So in about 3 minutes, I had Hazel back to sorting files into the proper buckets again. I thought I would share the process / tale of woe, in the event it might help somebody else in the future.
















