New Scripting Interface
Opus 10 provided a simple Active Scripting host that lets you write rename
scripts in any Active Scripting-compatible script language (VBScript,
JScript, etc).
Opus 11 expands this significantly. With scripts in Opus 11 you can, for
example:
- Query the state of Listers, tabs, paths and toolbars
- Obtain lists of files and folders and discover information about them
(basic information like name, size, date modified, etc, as well as metadata
like EXIF information, MP3 tags, etc)
- Write buttons and hotkeys functions purely from script code without
resorting to "Rename" hacks
- Test the state of certain system settings (similar to
@ifset in a traditional function)
- Build collections of files and run commands (Opus internal commands and
external programs) on them
- Display dialogs and popup menus
- Access the clipboard, environment variables and folder aliases
- Extend the list of Opus internal commands
- Automatically trigger scripts based on certain events
- Save and load configuration (Opus provides an editor that the user can use
to edit your script config)
There are two ways to use scripts with Opus (or three if you count the
existing rename script system).
- Script Functions
Script
Functions are defined directly in a button or menu - they provide a
third type of function alongside Standard Function and MS-DOS
Batch
Function.
The screenshot above is an
example of a script function that selects all "high-definition" images in the
current source file display (which are defined as images with a vertical
resolution greater than or equal to 1080 pixels).
The @script
directive is used to specify the scripting language -
VBScript is used by default if this isn't specified. For example,
@script jscript would specify a JScript script. The
OnClick function is a defined script entry point
that Opus will call whenever your button is clicked (or hotkey pressed). The
ClickData object passed to it provides a number of
properties and methods that you can use to interact with the Lister that
launched the function.
- Script Add-ins
Script Add-ins are script
files that are installed in the Opus Scripts folder (you can find
this folder by typing /dopusdata/Script AddIns into the
location field). Script add-ins are plain text files with an extension that
specifies the script language in use (e.g. a file ending with
.js would be a JScript script). One or more script
add-ins can be bundled, optionally with a set of icons, in an archive
called a Script Package (a zip file with the .osp
suffix).
Whereas script functions are only called whenever their button
is clicked, script add-ins can be called automatically in response to one or
more events. Each script can provide handling for one or more defined event
entry points, and Opus will automatically call on each script that provides
handling for the event in question. Some of the events that scripts are
notified for include when tabs are activate or deactivated, before and after
folder changes, when the view mode is changed and when Listers are opened or
closed. Script add-ins can also implement custom commands - this lets you
extend the Opus internal command set in a similar way to User
commands.
The new Toolbars / Scripts page in
Preferences displays a list of any add-in scripts that have been
installed. You can use the checkbox to enable or disable each
script.
If you select a script in the
list it reveals more information about it (a description, copyright
information, and a list of the commands and events that the scripts
implements). The About and Configure buttons
will be active if the script supports those actions. Clicking the Edit
button will open the script in your default text editor (standalone
scripts only).
You can easily install new scripts or script packages by
dragging and dropping them onto the Scripts list. You can also create
a new script using the Create New Script command in the
File menu of the Preferences dialog. This displays the
Create New Script
dialog:
Currently this dialog lets you create
a template for a JScript or VBScript script. Select the
desired language, and enter a name, optional description and copyright string.
Then use the checkboxes in the list to select the events that you want the
script to create functions for. The very last event in the list,
NewScriptCommand, lets you create a script that adds internal
commands. When you turn this option on it will activate and let you enter a
name for the command. Press return to accept the new name, and another
NewScriptCommand entry will be added to the list. In this way you can
easily create a template for a script that adds multiple internal commands.
The CLI tool has been enhanced to allow you to design and
test ad-hoc scripts. Turn on the Script interpreter option to enter script mode,
and select the script language from the drop-down field (or enter the
appropriate language name).
Press F5 or click the Run button to run
your script.
Any errors/warnings or text output from a script (via the
DOpus.OutputString function) will be displayed in the Other
Logs panel (part of the Utility Panel). You can choose the type of
information to display in the log using the Preferences / Miscellaneous
/ Advanced: script_output_level option.