How to integrate FileMerge.app into Finder?

Apple's xcode comes with a basic merge/diff app that is located at /Applications/Xcode.app/Contents/Applications/FileMerge.app.

I was searching in the FileMerge settings for some kind of option to 'Integrate into Finder' but there doesn't seem to be any integration available ootb.

What would it take in order to add the ability to select two files in Finder, right-click them and then have a Compare option in the dropdown menu?

Can this be achieved by editing some plist files and hooking some bash script or applescript?

Are there any generic examples of adding custom actions to the Finder context menu that act on selected files?


Solution 1:

You would use the Automator application to create a service. The steps are given below. The images are from Monterey.

  1. Open Automator, then highlight Quick Action, as shown below. When finished select the Choose button.

  2. Select "Workflow receives current files or folders in Finder", as shown below.

  3. Select Utilites, then drag Run Shell Script to the workflow area. The result is shown below.

  4. Select "Pass input: as arguments" and change any commands to the single command shown below.

    opendiff "$@"
    

    The result is shown below.

  5. Save the service as Compare, as shown below. When finished, select the Save button. The file is saved in your ~/Library/Services folder. You can quit the Automator now or after testing.

  6. To test, open a Finder window and highlight two files, then right click and select Compare. An example is shown below. The FileMerge application should open and show a comparison of the selected files.