Using Script Add-Ins to Expand Opus Functionality
When you come to Directory Opus, the word script may cause some confusion because Opus has several kinds of scripts.
✱ On another page, we look at rename scripts, which give you fine-grain control over renaming operations.
✱ Another page aims to introduce you to script functions, which can power the behavior of a button or keyboard shortcut.
✱ This page looks at script add-ins, which let you reach deep into Opus functionality, allowing you for instance to create custom columns or define what happens when you double-click a blank area of a lister.
Script Add-InsDirectory Opus 11 introduced a scripting interface that allows users to make Opus do new things by writing script add-ins in a variety of languages. At first, it could seem that this feature would only be useful to programmers. But it is not so. Soon after the launch of DO11, talented coders started posting a variety of useful script add-ins on the forum's scripting page. If you invest a few minutes to learn how to install a script add-in, you will gain access to a treasure trove of new features.
Before DO11, Opus allowed users to create renaming scripts (in the advanced rename panel) and script functions (inside buttons). This page is mainly concerned with the new kinds of scripts introduced in Directory Opus 11: script add-ins, which are installed in the new Scripting panel under Preferences. Rather than give you an abstract list of a script add-in's capabilities, I'll let you browse through the script add-ins presented below.
This page does not aim to teach you how to write script add-ins for Opus. Instead, it aims to:
✽ explain how to install script add-ins.
✽ present a number of script add-ins I have found useful
✽ point to resources for those who wish to code their own script add-ins.
On a dedicated page, my own contribution is the "file name database" script add-ins that let you define file naming conventions to add metadata to your files (such as movies and comics) and see that data in columns.
Installing Opus Script Add-InsInstalling a script add-in is usually a two-step process:
✽ Step 1. First, you download the script file (usually a js or js.txt file) to your machine. You then install the script itself by going to Prefs / Toolbars / Scripts and dragging the file from the lister to the right pane of the Preferences panel.
✽ Step 2. Next, for some scripts, you create a button (or series of buttons) that call the script, possibly passing some parameters. To do so, typically you would Alt-click an empty space on the toolbars to enter Customize mode (assuming you've activated Prefs / Toolbars / Options / Alt-click to edit toolbar buttons), then click inside a menu and choose Insert New / New Button, then paste a command inside the button and possibly assign it a hotkey.
For instance, after installing the Select Random script add-in, you can create one button containing SelectRandom in the Function box to select a random file, and another button containing SelectRandom FILES ITEMCOUNTPERC=50 to randomly select half the files in the lister.
That's it! Your script is ready to go.
Occasionally, you need to configure the script add-in by selecting it in Preferences / Toolbars / Scripts and clicking the Configure button… or even by editing the code of the script itself.
Skipping Step 2
If you are using my toolbars from 15 February 2015 or later, for the scripts on this page you can skip the second step as buttons (which you can tweak) live under Tools / Script Add-Ins.
Updating Script Add-Ins
As bugs are fixed and new features implemented, script authors often post new versions on the forum page corresponding to their script. To keep abreast of updates, you could become a frequent visitor of the Scripts section of the Opus forum, but for many scripts there is a simpler solution. Using the ScriptWizard script, you can update all compatible scripts without leaving Opus.
Under the ScriptWizard button's pull-down menu, select Go Script Addins. This opens the Opus folder where scripts reside. Selecting scripts, you can then select Update or Check for Updates under the same pull-down menu.
A (Very) Incomplete List of Script Ad-InsAny list of scripts necessarily represents the compiler's own bias, itself a result of his perceived needs. I therefore recommend you explore scripts at your leisure in the Scripts section of the Opus forum.
Nevertheless, to give you an idea of the range of functions made available by scripts contributed by the Opus community, this section presents a number of scripts I have found useful. If your script is missing, please don't be upset—I may not have noticed it or found a fit for my particular workflow.
For easy navigation, here are some jumping points to the scripts on the page:
✽ Go Sibling
✽ Select Random
✽ Confirm Multi Open
✽ Close Tab Siblings
✽ CBX Handler (Comic Book Reader)
✽ Compare Tabs
✽ Hash Compare
✽ Line Counter
✽ Regex Columns
✽ Go Registry
✽ Toggle Thumbnails
✽ Lister Double Click
✽ Rename from Clipboard
✽ External Compare and Merge
This terrific script by Leo lets you add buttons that cycle forward or backwards through folders that share the parent of the current folder. Added to my toolbars, under the Go menu.
This script by tbone allows you create buttons that select a number of random files—and possibly do something with them. For instance, one button can select half of a folder's files and create a slideshow. Another button can select ten files and send them to your music player. On my toolbars, buttons for this script live under Tools / Script Add-Ins / Select Random.
This script by tbone is probably one you should consider installing once you have picked one or two scripts you like. Among other features, it allows you to update scripts you have installed. Another feature I like is that it defines custom columns that you can use in a layout to view information about your scripts, as shown in the picture below.
Confirm Multi Open
This script by jsys asks you to confirm when you try to open a large number of files (you specify the threshold). Have you ever selected a thousand files and pressed Enter by mistake? All these files might spawn a picture viewer or text editor window. This is the kind of situation this script aims to rescue you from. This script does not require a button.
Close Tab Siblings
This script by tbone tries to prevent this:
All too often, lost in work, some of us tend to navigate to a folder that is already open in another tab. When the script detects this, it closes the original tab for you. Keep it tidy!
When you click on the script on the Prefs page, some options come up. For me, StartIndex had to be set to zero. It also looks like you can make a list of folders the script should ignore.
CBX Handler (Comic Book Reader)
With this script by steje installed, when you click on a comic book format such as cbz or cbr, the book opens in the standalone image viewer, which lets you browse the pages. (You probably know that these formats are nothing other than a zip or rar file with a renamed extension.) I never got used to ComicRack, so I love this script. There are a number of configuration options, which you can access directly by clicking the script name under Prefs / scripts in DO12.
In a dual lister, this script by aprold selects the files that are missing from the other lister. On my toolbars, a button for this script live under Tools / Script Add-Ins / Compare Tabs.
This script by steje lets you check if the selected file has the same MD5 or SHA-1 hash as the text in the clipboard. On my toolbars, a button for this script live under Tools / Script Add-Ins / Hash Compare.
This script by aussieboykie lets you select one or multiple files and count the lines of text in the files it contains. On my toolbars, a button for this script live under Tools / Script Add-Ins / Line Counter.
This script by tbone adds several columns with information about the selected text files: number of lines, encoding (e.g. UTF-8), style of line endings (e.g. \r\n for Windows, \n for Unix). After installing, you can add the desired columns in the usual way: right-click / Script / ColumnFile:FileInfo
This script by wowbagger was the inspiration for my "file name database" scripts. It lets you define custom columns based on the file name using regex, a tool dear to my heart. On the image, you can see how the two custom columns hero and score have been defined to extract the hero's name and the number from the file name.
At the moment, the configuration process for the script is a little heavier than for some other scripts. The script is provided as an osp file. Assuming you haven't set a handler for osp files, rename the extension to zip, and extract the contained archive, which is a js file. (Alternately, add "osp;" in Prefs / Zip & other archives / Zip Files / Zip Extensions.) Then edit the file, which contains the column names and definitions, for which you'll need to know a little regex. (If you're new to regex, I suggest you visit my regex site.)
In my view this feature is immensely valuable because it lets you create complex file-naming conventions containing file metadata. For instance, you could name your movie files according to a convention such as rating-title-year-director. Using regex columns, you can now sort movies not only by regular file attributes such as file name and size, but also by their rating, title, year and director. On my "file name database" page, you can see examples of this for movies and comics.
I made a small modification to this script support capture groups (the post has an attached script you can install alongside the original).
This script by tbone opens Regedit and makes it jump to the registry key in the clipboard—saving you a lot of navigation time.
Try it for instance by copying HKEY_CURRENT_USER\Control Panel\Desktop
On my toolbars, a button for this script live under Tools / Script Add-Ins / Go Registry.
This button and script package by tbone allows you to switch between Details and Thumbnails mode while keeping the same files selected. I like it so much I've assigned it to Ctrl + S. On my toolbars, a button for this script live under Tools / Script Add-Ins / Toggle Thumbnails.
Lister Double Click
This script by tbone extends the actions Opus takes when you double-click on an empty space in a lister. As you may recall, clicking an empty space on the lister goes up to the parent folder (as does pressing the back button). Now, in addition,
✽ Shift-double-clicking an empty space copies the path of the current folder to the clipboard, saving me the F4 / Ctrl + C combination I seemed to be doing ten times a day;
✽ Ctrl-double-clicking an empty space navigates to the path currently present in the clipboard, saving me the F4 / Ctrl + V combination I seemed to be doing just as frequently.
This script does not require a button.
Rename from Clipboard
This script by tbone allows you to copy a list of desirable file names, select an equal number of files, and click a button to rename all the files with the names in the clipboard. On my toolbars, a button for this script live under Tools / Script Add-Ins / Rename from Clipboard.
This script by jon creates the GoExisting command that opens a tab with the specified path. If that path already appears on a tab on either side of a lister, that tab is focused. Usage: GoExisting somepath
On my toolbars, this script is used in the shortcuts to go to the desktop (Shift + Home), go to the recycling bin (Alt + Del) and empty the recycling bin (Ctrl + Shift + Del).
External Compare and Merge
wowbagger wrote a well-regarded script that allows you to use a variety of external tools (such as BeyondCompare) to compare and merge folders. I do not use these tools so I haven't had a chance to try it.
Resources for CodersThis section is not a scripting manual. Rather, it aims to present basic information and collect resources to get you started fast.
Choice of Language
You can actually use any active scripting language to write Opus scripts, but since Windows doesn't ship with ActivePython and ActivePerl (PerlScript) installed, the reach of your scripts will be reduced if you use these languages. On the other hand, JScript and VBScript are supported out of the box.
Getting Started Writing a Script
There are various kinds of Opus scripts, and you create them in various places. Although the focus of this page is script add-ins, it's worth mentioning the other kinds of Opus scripts.
✽ Rename scripts. To create a Rename script, open the Advanced Rename panel and check the Script Mode box.
✽ Script-in-a-button. When you enter Customize mode to edit a button, press Advanced at the bottom of the box and select Script Function from the Function pull-down menu.
✽ Script add-ins. Under Prefs / Toolbars / Scripts, the File menu at the top left of the window has a Create New Script item that lets you create a stub. You will find this stub in the /dopusdata/Script AddIns folder (I'd suggest adding this folder to your favorites).
Here are some Opus scripting that seem useful to me. If you know some particularly useful posts, please send them along in the comments section.
✽ Your first stops should be the Manual's scripting section, then the example scripts and scripting reference.
✽ tbone wrote an article on Script Initialization using Script.config items.
✽ tbone wrote a ConfigHelper class you can paste in your scripts to help create configuration items.
✽ MrC wrote a post explaining how to set up ActivePerl for DO11 scripting.
✽ Leo explained why scripting Opus with ActivePython may not be the best idea even though it is supported. It seems to me that his points largely extend to ActivePerl.
Other Types of Scripts in Directory Opus