Perforce Public Knowledge Base - Command line P4Merge on Mac OS X
Reset Search



Command line P4Merge on Mac OS X

« Go Back



Using P4Merge from the Mac OS X command line.

Using a third-party diff/merge tool from the Mac OS X command line.


There is a small helper application embedded in the P4Merge application that enables running P4Merge from the OS X command line. We refer to this helper application (launchp4merge) as a "shim".

The shim is a part of the P4Merge application bundle and should not be removed or renamed. To use the shim you must write a small shell script.

  1. Using a text editor, create a file called containing the following two lines:

    <path to P4Merge>/ $*

    Replace  <path to P4Merge>  with the real path to the P4Merge application. If you placed P4Merge in the standard Applications directory, the script will look like this:

    /Applications/ $*
  2. To use the script, you must make it executable. Enter the command:

    chmod +x
  3. Place into the /usr/bin directory (or any directory set in your $PATH environment variable).

After these steps are completed, you can run launchp4merge from the command line. For example, to diff two files, enter the command: /path/file_1 /path/file_2

You can pass command line options to launchp4merge as well. To see a list of options, enter -h and a listing of launchp4merge command options is displayed in the Terminal window.

You can start as many shim processes as you require. Each launchp4merge process is attached to the resulting window in the P4Merge application. When the window is closed, the process terminates automatically.


To use a third-party diff/merge application, you would use an approach similar to the above example. For example, to use "kdiff" as your diff utility, you would create a file called containing the following lines:

exec /Applications/ "$1" "$2"

Then proceed with steps 2 and 3 as in the first example, substituting as the filename.


An alternative to using shell script is to add an "alias" to the shell profile. For example, for the bash shell add the following line to the .bashrc file in the home directory:

alias p4merge='/Applications/

Now running p4merge against to relative files in the current working directory will work in the form of:

p4merge file1 file2
Related Links



Was this article helpful?



Please tell us how we can make this article more useful.

Characters Remaining: 255