One of the aspects of being a professional software developer that is a real grind is the tedious, careful double-checking we must do in order to reduce the odds that our work will lead to some major metropolitan area bursting into flames.
Double-checking means diffing.
Diffing is hard. Even with somewhat friendly tools at our disposal, it’s a tedious, annoying pain in the butt. It doesn’t help that diff tools don’t seem to have improved much in the past 10 years, and are still obnoxiously finicky when it comes to issues like line-endings, encodings, etc.
But the worst part of diff tasks, as with most things, is simply getting started. I am particularly averse to working on things that are hard to start. While diffing from Xcode can be really easy just hit a keyboard shortcut to see a comparison with the last checked-in copy, for instance), diffing arbitrary files in the Finder usually follows a pattern more like this:
- Launch a diff-comparison tool like BBEdit or FileMerge.
- Navigate to File A in the Finder. Drag it to the diff-tool.
- Navigate to File B in the Finder. Drag it to the diff-tool.
- Tell the diff-tool you’re ready to compare!
Well, that’s too many steps for me. So I wrote an AppleScript to apply some rather straightforward logic to the selected items in the Finder, and open your favorite diff-tool for you with the comparison process started. The logic of the script is simple enough:
- Are there two items selected in front window? Compare them.
- Is there exactly one item selected in the front window and one item selected in the second-to-front window? Compare them.
Here, “compare them” means pull an Xcode-like move and launch the “diff opener tool” of your choice. I’ve included in the script the paths to two “secret tools” used by Xcode for opening with BBEdit and FileMerge. If you want to use a different tool you’ll have to find a way of invoking it directly with two full paths, or write a helper tool that can do the trick for you.
This simple script makes a great Cmd-Opt-C shortcut in the Finder. It’s the same shortcut I use for “compare with latest” in Xcode. Now when I see two files in the Finder that I want to compare, I just select them both and trigger the script. Wham!
Feel free to download the script: Compare Files. Let me know if you have any suggestions for improving it.