Package com.deltawalker.script
Running scripts
Scripts are plain JavaScript run by the GraalJS engine built into
DeltaWalker Classic. Open a script with File > Script > New or
Open... and run it with Cmd+Shift+R (Ctrl+Shift+R on Windows
and Linux); anything the script writes with console.log(...) or
console.error(...) appears in the Console. The sample scripts that
ship with DeltaWalker Classic are a good starting point: each one is a
workflow in the Workflow Gallery (File > Script > Workflow
Gallery...), where Open Source opens it in the Script Editor.
Global objects
App- theAppobject, the entry point to everything else: comparisons, settings and the main window.dw- another name for the sameAppobject.workflow- present only when a script is run as a configured workflow with parameters. It maps each parameter id to its value, always a string, for exampleworkflow.REPORT.
Every public method and field of the objects in this package can be called
from a script. Enums and classes such as Role
or Comparison.Type are loaded with
Java.type(...):
const Comparison = Java.type('com.deltawalker.script.Comparison');
const ReportKind = Java.type('com.deltawalker.script.ReportKind');
const SettingKey = Java.type('com.deltopia.io.SettingKey');
Long-running operations and await
Comparing, merging, synchronizing, reporting and printing run in the
background. The methods that start them return immediately with a
thenable - a native JavaScript Promise or a
ScriptOperation - that settles when the work
is done. The script runner wraps every script in an async function,
so await can be used at the top level without any wrapper:
const Comparison = Java.type('com.deltawalker.script.Comparison');
const ReportKind = Java.type('com.deltawalker.script.ReportKind');
const HOME = App.getProperty('user.home');
const comp = App.getComparisons().create(Comparison.Type.FOLDER,
[HOME + '/Documents', '/Volumes/Backup/Documents'], null);
try {
await comp.compare();
console.log('Differences found: ' + comp.hasDifferences());
await comp.report(HOME + '/Desktop/backup-report.html', ReportKind.HTML, null, null);
} catch (e) {
console.error('Comparison failed: ' + e);
}
Operations on different comparisons can run at the same time, for example
with await Promise.all([a.compare(), b.compare()]). A single
comparison runs one operation at a time: starting a second operation while
one is still pending on the same comparison fails. See
ScriptOperation for how operations succeed,
fail and are cancelled.
- Since:
- 2.0
-
ClassDescriptionA folder comparison filter that lets files and folders with different names be matched and compared, using a pair of regular or shell expressions.The entry point of the DeltaWalker Scripting API.A folder comparison filter that excludes or includes files and folders with a given attribute, such as hidden or writable.Signals an attempt to access a position that does not exist in a text document, for instance an offset beyond its end.The base type of all comparisons - folder, text and image.The individual comparison methods - by size, date, attributes, as text, and byte by byte.The states reported to a
ComparisonListenerthroughComparisonEvent.getState().The supported types of comparison.An event delivered to aComparisonListenerwhen the state of a comparison changes, for instance when a comparison starts or ends.Receives theComparisonEvents of a comparison.Creates comparisons and gives access to existing ones, including the comparison history - comparisons created earlier whose settings were saved so they can be run again.A difference found by a comparison: one or more pairs of comparable items - files and folders, blocks of text - together with theDelta.Kindof difference within each pair.The kinds of difference between the two items of a relation.A node in the results of aFolderComparison: one file or folder, with theResourcefound at eachRoleand the result of comparing them.Details about how the resources of aDeltaNodediffer, returned byDeltaNode.detail(Role[]): theComparison.Methods that found differences; forComparison.Method.AS_TEXT, the numbers of added, deleted and changed blocks of text; forComparison.Method.DATE_MODIFIED, the difference between the last-modified times.A block of text found by aTextComparison: an offset and a length in the document of eachRole, together with theDelta.Kindof difference.Represents the duplex mode a printer might possibly support.AComparisonof individual files - text or images.The base type of all DeltaWalker filters.An ordered collection ofFilters, obtained withSettings.filters(Comparison.Type).AComparisonof folder hierarchies.The base type of all folder comparison filters:AlignFilter,AttributeFilter,PathFilter,SizeFilterandTimeFilter.What a folder filter applies to: files, folders, or both.An entry in the comparison history: information about a comparison that is sufficient to re-create it and run it the same way later.AComparisonof images, compared pixel by pixel.Defines the units of measurement for the margins of printed pages.The merge operations available in text comparisons.The orientation of printed pages.The page settings used when printing comparisons: orientation, margins, header and footer.The formats of aReportKind.PATCHreport.A folder comparison filter that excludes or includes files and folders whose name or path matches a shell or regular expression.The printer settings used when printing comparisons: the printer, number of copies, page range, duplex mode and printing to a file.Which pages to print.Receives progress notifications from a long-running job, such as a merge, and lets the caller cancel it.Instances of this class represent rectangular areas in an (x, y) coordinate system.The kinds of report a comparison can write.Which linked reports to create with an HTML folder comparison report.A file or folder taking part in a folder comparison, on a local disk or on a remote server such as an FTP server.File and folder attributes.The role a compared item - a file, a folder, a block of text - plays in a comparison.The value an operation rejects with when it is cancelled, for instance because its comparison was closed while the operation was pending.A long-running operation - compare, merge, sync, report or print - that scriptsawait.A collection of settings and the operations on them.A folder comparison filter that excludes or includes files by size.Defines the possible file size units.The attribute to sort the resources of a folder comparison by.Specifies the direction in which to sort a list of items.The synchronization operations available in folder comparisons.Receives progress notifications from folder synchronization and deletion jobs, and lets the caller cancel them.AComparisonof text files.A text comparison filter that makes the comparison ignore text matching a regular expression.A folder comparison filter that excludes or includes files and folders by their last-modified time.The location of a resource together with the information needed to access and read it: for a resource on a remote (S)FTP(S) server, the user name and password, or the SSH key and passphrase; for a text file, the character encoding and line ending to read or save it with.The properties aUriInfocan have.The main DeltaWalker window, obtained withApp.getWindow().