Death-Diffying Moves

December 29th, 2005

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:

  1. Launch a diff-comparison tool like BBEdit or FileMerge.
  2. Navigate to File A in the Finder. Drag it to the diff-tool.
  3. Navigate to File B in the Finder. Drag it to the diff-tool.
  4. 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:

  1. Are there two items selected in front window? Compare them.
  2. 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.

3 Responses to “Death-Diffying Moves”

  1. Eric Albert Says:

    I use bbdiff or opendiff, depending on whether I feel like using BBEdit’s diff or FileMerge. For me at least, that’s a lot faster than finding the files in the Finder.

  2. Daniel Jalkut Says:

    I wonder what the mysterious “comparefiles” used by Xcode does that bbdiff doesn’t. Perhaps it’s just so Xcode has something to point to if BBEdit isn’t installed?

    I often end up looking at files in the Finder when the instinct to compare them arrives :) I would agree it’s easier to use a command line tool if you have the paths handy and you’re already in there.

  3. Nate Says:

    That’s great, thanks!

    I actually use BBEdit as my remote diff-ing tool, since one project I’m working on has multiple developers with no CVS in place — edit the local, open the remote through Transmit, then shift-click the two files in the document drawer and choose “Compare Selected Documents.”

Comments are closed.

Follow the Conversation

Stay up-to-date by subscribing to the Comments RSS Feed for this entry.