Beyond Compare provides a script processing feature which allows you to automate routine tasks. A script is a simple text file containing a list of commands which can control the program and automatically perform file operations or produce reports. See Scripting Reference for a list of all scripting commands.
Scripts run without displaying the usual Beyond Compare user interface, but might require input for certain confirmations. Scripts essentially manipulate an invisible folder session: file operations require selections, the "display" can be limited with filters, and folders can be "expanded" to recurse into them. Any folder name argument can be a folder on your system, on the network or a remote service, or the name of an archive file such as .zip, .cab, or Beyond Compare Snapshot file.
Running a script
Specify the filename of the script on the command line with a leading "@" symbol, as in:
BCompare.exe @"C:\My Folder\My Script.txt"
bcompare @"My Folder/My Script"
Creating a script
Scripts are processed line by line, with a single command per line. Scripts are not case sensitive, and blank lines and comments (anything after a "#") are ignored. Arguments are separated by spaces. To include a space in an argument, surround the argument with quotes ("). To continue a long command on a second (or third) line, add an ampersand (&) at the end of every line but the last.
A parameter specified on the command line can be referenced by inserting a percent sign (%) followed by a single number from 1-9. The script name and command line switches starting with / are not included in the 1-9 list. Given the command line:
BCompare.exe @"My Script.txt" /silent "My Session"
the session named "My Session" can be loaded by adding the following to the script:
load "%1"
An environmental variable can be inserted by enclosing its name in percent signs. The character case of the environmental variable must be correct. The system's temporary folder can be loaded by adding the following to the script:
load "%TMP%"
There are several dynamic variables that Beyond Compare can fill in at each line of the script. The %date% variable fills in the current date in the format yyyy-mm-dd. The %time% variable's format depends on your computer's regional settings. The %fn_time% variable outputs the time as hh-mm-ss, which can be used for filenames.
Scripting command line switches
Note macOS and Linux users should prefix the switches with "-" instead of "/".
The command line switches that affect scripting are /closescript, /leftreadonly, /readonly, /rightreadonly, and /silent. Normally, script processing adds an entry on the Task Bar and displays a Scripting Status Window detailing its progress and any errors. The /silent switch bypasses the Task Bar entry and Scripting Status Window, allowing Beyond Compare to process the script invisibly.
Scripting options
To change the script processing options, pick Tools > Options , switch to the Tweaks page, and then scroll to find Scripts. Mark the Beep when finished checkbox to have Beyond Compare sound an audible beep when it completes script processing. This beep can alert you to check and close the Scripting Status window. Close when finished causes Beyond Compare to automatically close its Scripting Status window when it completes script processing. When used in conjunction with Beep when finished, the beep simply tells you the process has completed.
There is also a place to designate a Shared scripts folder. When you provide a script name argument on the command line with no path designation, and there is no file of that name in the current folder, Beyond Compare will look in the Shared scripts folder for that script.