You were just about to get up from a hard day's work--editing application documentation, or was it the final essay questions for your computer science class or, perhaps, the last-minute ReadMes for your company's next 20 beta releases. Your boss, resembling that pointy-haired rat fink of Dilbert fame, stops you in your path: The uber-boss wants to change at least 10 of those ReadMe files--for delivery tomorrow morning. Put the coat back on the rack, and resign yourself to another missed dinner with the loved one(s)? Not a chance. FileMerge to the rescue!
In my last article, I talked in brief about those Xcode 2.2 applications from the Developer tools package (available from your Tiger Install Disc I, or free from http://developer.apple.com when you sign up as an online member), and at some length about PackageMaker as an automated means to install applications, text files, and other items to your users' machines, preferably from the comfort of your own desk.
The other applications that might come in handy for you, the non-programmer, are:
In this edition of "Xcode for Non-Programmers," we extoll the virtues of FileMerge.
No, that isn't a typo or smart-aleck spelling in this article's title. FileMerge goes way back to Unix's diff command.
If you man diff at the command line, here is its definition, according to the GNU pundits:
Figure 1. man diff
What does this mean? It says that you can do a line-by-line comparison of output from one text file against another. Please note: we're talking about flat files only. None of what we discuss below will work on Word, Excel, or other types of formatted files.
So far, though diff sounds great, right? Well, perhaps you are the kind of person who likes to watch paint dry, too.
What about that other command you may have heard about: opendiff? Let's man opendiff and see what the diff (heh) is.
Figure 2. man opendiff
If you scroll down the man page (using your space bar), you'll see that both opendiff and FileMerge are included as part of the Mac OS X Developer Tools, opendiff being a binary and FileMerge being an application. Does that mean you can use either the command line or the GUI tool to do your work? Yes.
Let's start with opendiff. If you try to search for opendiff in the Finder, you will come up empty-handed. As Mary Norbury-Glaser explained in her excellent series about Terminal, you can either navigate your way at the command line to the /usr/bin/ directory and run the opendiff command from there:
Figure 3. Go to folder
Or you can go to the folder from the Finder's Go menu:
Figure 4. opendiff in /usr/bin
Let's face it: if you are like most Mac OS X users, it's GUI, baby, all the way. Let's go and find FileMerge.
|
Related Reading Running Mac OS X Tiger |
|
If you installed the developer tools, you will find FileMerge here:
Figure 5. FileMerge location in hierarchy
Let's get started. Double-click on FileMerge and here is what you see:
Figure 6. FileMerge interface
I took most of the text you are reading now, copied it to another text file and made a few small changes ("diff" to "spiff," "command line" to "Terminal," et. al).
Figure 7. My original files
Here is the way you can use FileMerge quickly. Simple drag one file from the Finder to the left well:
Figure 8. Drag and drop your original file from the Finder
Then, drag and drop your other file from the Finder to the right well, and click the Compare button. Here is what you will see:
Figure 9. What you see in the compare window
First, you see the file you dragged to the left well on the left-hand upper portion of the screen, and the file you dragged to the right well on the right-hand side of the screen. The blue highlighting with the grey swish shows you where the differences are between the two files. Wow, we certainly have a few differences between the two files. Imagine spending all night with Find/Replace from the File menu--no way!
When I choose the first diffed line, the Actions drop-down menu is activated:
Figure 10. The action drop-down menu in action
You can choose to move data from left to right, right to left, choose both (left or right first) or, my favorite, choose neither. You can see the differences you want to keep, and those you want to toss. I am going to choose an amalgam of both, and save the merged files as the new MDCII_FileMergeBogus.txt:
Figure 11. Saving the merged files
Now I want to re-compare the merged files. How to do this? Simple: go up to the File menu and choose Recompare Files. Here is what I get:
Figure 12. Re-comparing merged files
Way too tedious. Why not hold down your Shift key and highlight everything?
Figure 13. All differences highlighted
You can then save the merged file.
|
But wait--there's more (cue the Ginsu knives)! Pull up the slider from the bottom of the screen. What do you see? It reveals your "what if" scenario, should you take the highlighted difference and apply it to your original text file!
Figure 14. Your "what if" scenario graphically revealed
If we can do this with individual files, what about directories (UNIX-speak for folders)? Of course! Here are two folders with a few differences between the two:
Figure 15. Two directories with a few differences
Let's see how we can compare the directories quickly. Do what you did before--drag and drop each directory into its own well, and click Compare.
Figure 16. Picking two directories for comparison
After initialization, you see a different view of the folders' contents:
Figure 17. Folder content comparison
You can filter out what is identical from one to the other, or show which files are different from one to the other (the Added/Deleted checkbox). You can choose to combine, remove or unmark files using the drop-down menu. I will chose to combine the files by highlighting them, and save all of the files with a new name:
Figure 18. Your directory merge choices
Let's see if that worked:
Figure 19. Creating a new directory from two merged directories
Figure 20. The merged directories as a new directory
Go ahead and get all those files merged and then put them in new merged directories--then go home to a great dinner. First, check your email. It's your boss again, asking if you make certain "things" happen when people launch Safari or other applications. You think, "Is he nuts?" He might be, but you can make applications sit up and beg--with Property List Editor. Tune in next time for more fun with Xcode tools.
Shelley Weiner is president of Business Rules, Inc., a technical training and Macintosh consultancy located in the beautiful Hudson Valley of New York State. She is an Apple Certified Trainer, an Apple Certified Systems Administrator, and a member of the Apple Consultants Network.
Return to the Mac DevCenter
Copyright © 2009 O'Reilly Media, Inc.