Scripting DeltaWalker Classic
DeltaWalker Classic runs scripts written in JavaScript. A script can do everything you do by hand — open file and folder comparisons, wait for them to finish, look at what changed, merge, synchronize, print, and write reports — so a job you repeat every day becomes one click.
Scripting is part of DeltaWalker Classic Pro and Oro, and of the trial. DeltaWalker Classic Standard runs the ready-made workflows but not scripts of your own. DeltaWalker Classic Free and the Mac App Store edition do not include scripting.
Three ways to run a script
- Run a workflow. Workflows are ready-made scripts for everyday jobs such as verifying a backup or finding files that were never copied. Click Workflows on the main toolbar, or choose File > Script > Workflow Gallery…, pick one, fill in its folders, and run it. See Workflows.
- Write your own. Choose File > Script > New or File > Script > Open… to open a script in the Script Editor, then press Cmd+Shift+R or click the round run button in the editor’s top-right corner. Output appears in the Console. See Script Editor and Debugger.
- Run it from the command line. Start DeltaWalker Classic with
-script=<path to script>and it opens the script and runs it. See Command Line.
Your first script
const Comparison = Java.type('com.deltawalker.script.Comparison');
const comparison = App.getComparisons().create(
Comparison.Type.TEXT, ['/path/to/old.txt', '/path/to/new.txt'], null);
await comparison.compare();
console.log('Deltas: ' + comparison.getAllDeltas().length);The script opens a text comparison window, waits for the comparison to finish, and prints the number of deltas to the Console. (A folder comparison counts its deltas with getDeltaCount().) With two paths, the first is the Reference and the second the Modified side.
What a script can use
Appis the starting point for everything else.App.getComparisons()creates and lists comparisons,App.getSettings()reads and changes settings,App.getWindow()moves and resizes the main window, andApp.getVersion(),App.getEdition()andApp.getProperty(name)tell a script where it is running.dwis a shorter name for the same object.workflowholds the values a person entered in the Configure Workflow dialog, when the script runs as a workflow.workflow.SOURCE, for instance, is the folder chosen for the field with the idSOURCE.Java.type(...)loads a type of the scripting API, such ascom.deltawalker.script.Comparisonorcom.deltawalker.script.ReportKind, to reach its constants.console.log(...)andconsole.error(...)write to the Console. Error output is shown in red.
Every script runs inside an async function, so you can write await anywhere. Comparing, synchronizing, merging, printing and reporting take time, and the methods that start them return straight away with an operation you can await:
await comparison.compare();
await comparison.report('/path/to/report.html', ReportKind.HTML, null);
// Two comparisons at the same time; this takes as long as the slower one.
await Promise.all([first.compare(), second.compare()]);Wrap the work in try/catch to handle a comparison that fails, for example because a folder does not exist.
The Scripting API Reference
The Scripting API Reference describes every object, method and constant a script can use.
Sample scripts
DeltaWalker Classic comes with more than twenty sample scripts, from simple backup checks to three-way merges and remote folder comparisons. Each one is a workflow in the Workflow Gallery, where Open Source opens it in the Script Editor so you can read it, change it, and save your own copy. The files themselves are in the samples/scripting/javascript folder of the DeltaWalker Classic installation — on macOS, inside the application: DeltaWalker Classic.app/Contents/Resources/samples/scripting/javascript.