Have you ever tried to compare 2 files on OSX? It’s possible with FileMerge, but it is not so convenient. So I tried to find a way that makes it possible to select a file in Finder as a reference file and then a second file you want to compare with it. Of course I could use the Terminal, but the goal was to do it in the GUI with the Finder. Here is how I do it. If you have a better way let me know.
1 - create a new service
Start ‘Automator’ and create a new Service.
2 - select “run shell script”
Select “Run Shell Script” from the “Utilities” category.
3 - compare this …
Make sure the settings are like in the image. Service receives selected files or folders in Finder. Shell is /bin/bash and pass input as arguments. And then echo the first parameter $1 (which will be the file you select in the active Finder window) and redirect it into a file of your choice. I use ~/.compare which would be a hidden file in my user home directory. Save this service with a proper name e.g. “compare_this”.
echo $1 > ~/.compare
4 - … to that
Repeat the steps 1, 2 and half of step 3 and then instead of the echo you call your diff/merge tool with what is selected now in Finder and compare it with what we selected before. So in case of MacVim it’s …
/usr/local/bin/mvim -d $1 `cat ~/.compare` &
Save the Service as e.g. “compare_to_that”. Explanation - /usr/local/bin/mvim is my MacVim, -d is the parameter which starts Vim in diff mode, $1 is the file we currently selected in the Finder window,
cat ~/.compare means put the content of the file right here (cat is for printing files and the backticks put the output of cat right there; $(cat ~/.compare) maybe also works, I haven’t tried it), and finally the & ampersand to run MacVim in the background so the we do not wait for the process to finish.
If remember correct that’s all. Nothing more to do. The services should be now be available in the context menu in Finder. If you like you can go the keyboard settings and give hotkeys to both services.