Recently I’ve been needing an easy way to paste two versions of a text, and get the differences between the texts, specifically changes within a line (most diff programs only show which lines have changed). After some searching, DiffMerge came up as one of the best free diff programs that would work on the Mac. DiffMerge is great in many aspects, however, it lacked the interface to paste in text to diff right off the start.
I set out using Mac’s Automator tool to create an application to prompt the user for two texts, create the temporary files, then pass it into DiffMerge.
I came up with the following workflow:
- Get value of a pseudo-variable – random identifier
- Set the value of the random identifier into a variable so the same identifier can be referenced later (subsequent steps refer to this value as just the “identifier”)
- Ask for base text
- Store base text in a temporary file (using the identifier as part of the filename)
- Ask for new text
- Store new text in a temporary file (using the identifier as part of the filename)
- Get value of the identifier
- Run a custom shell script to open up diffmerge with the files created in the steps above. Passing in the identifier as an argument of the shell script allows us to figure out the name of the temporary files. The shell script also removes the temporary files when DiffMerge is closed.
The result was quite successful. Here is what DiffMerge looks like after pasting in two SQL dumps into the Automator application. Notice the temporary filename.
Many times, computers programs are born out of necessity to reduce repetitive or menial tasks. For Mac users, Automator’s a nifty tool that can help with that.
If you have used Automator for anything cool, let me know in the comments!