Description:
This script Add-In will make Directory Opus ask you to confirm before opening more than X (configurable, 20 is default) selected items by keyboard Enter key.
I was inspired to make this script Add-In when it happened that I had about 200 high-resolution HD images selected and accidentally pressed Enter (workflow sequence derailed) and then chaos ensued: IrfanView (fastest image viewer for Windows) instances started multiplying and soon the computer became unresponsive (mouse froze) from so much load (RAM was quickly filled and paging-fest started) for several long minutes (I didn't want to reset the computer so I waited).
Now such things shall never happen again!
Installation
- download ConfirmMultiopen.js.txt (attachment below)
- in your Directory Opus go to Settings > Preferences... then Toolbars > Scripts
- now simply drag & drop downloaded ConfirmMultiopen.js.txt to the Preferences window, and that's it!
Usage
There is nothing special you need to do, after installation this Add-In is immediately active. See Changing Settings below to configure it to your needs.
Changing Settings
You can configure this Add-In by going to Settings > Preferences... then Toolbars > Scripts and then selecting Confirm multi-open Add-In in the list and clicking its Configure button.
-
Threshold setting: for example if threshold is 20 you'll get prompted to confirm (screenshot above) in the event that more than 20 selected files/folders are to be opened at once. You can set it to any value, even 0.
-
Excluded extensions setting: list of name endings (you are not limited to pure extensions) which will not count toward the threshold limit (remove the example extensions from the list before adding your real ones).
-
Focus button setting: lets you change which button (Proceed or Cancel) is to be focused when confirmation prompt is triggered. Default is Proceed so when confirmation dialog pops-up you can just press Enter again to proceed.
Uninstalling
You can manage Add-Ins in Directory Opus Preferences; Settings > Preferences... then Toolbars > Scripts.
Download
Version 1.1b (Maintenance; removed no-longer-maintained ScriptWizard support.)
ConfirmMultiopen.js.txt (7.7 KB)
Older versions
Version 1.1 (Added "Excluded extensions" feature. Opus version 11.10.2 or higher is required.)
ConfirmMultiopen.js.txt (9.76 KB)
Version 1.0 no longer available.
Script Code
The script code from the latest version is reproduced here for reference:
// Confirm multi-open
//
//
// This is a script for Directory Opus.
// See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData) {
initData.name = "Confirm multi-open";
initData.desc = "Ask before opening more than X selected items by keyboard Enter key.";
initData.copyright = "bytespiller 2014-2015";
initData.version = "1.1b";
initData.default_enable = true;
initData.min_version = "11.10.2";
// settings & defaults
initData.config_desc = DOpus.Create.Map();
var option_name = "";
option_name = "Excluded extensions";
initData.Config[option_name] = initData.Config[option_name] = DOpus.NewVector(".mp3 (example)", ".flac (example)", "_comic_page.jpg (example)");
initData.config_desc(option_name) = "Selected items with these extensions (name endings) will not count toward the threshold limit. No wildcards or regex.";
option_name = "Focus button";
initData.Config[option_name] = DOpus.NewVector(0, "Proceed", "Cancel");
initData.config_desc(option_name) = "A button on the multi-open confirmation dialog to have initial keyboard focus.";
option_name = "Threshold";
initData.Config[option_name] = 20;
initData.config_desc(option_name) = "Multi-open confirmation dialog is triggered on attempt to open more than this amount of items.";
}
// Called when a file or folder is double-clicked
function OnDoubleClick(doubleClickData) {
if (doubleClickData.mouse != "none") { // ensure we react only when *not* triggered by mouse (such as middle double-click)
doubleClickData.call = false;
return false;
}
return handleOnDoubleClick(doubleClickData); // from docs: "If you return True, the double-click will be cancelled and the file will not be opened. If you return False the double-click will be allowed to continue (this is the default)."
}
// ********************
// * Custom functions *
// ********************
String.prototype.endsWith = function(suffix) { // http://stackoverflow.com/a/2548133
return this.indexOf(suffix, this.length - suffix.length) !== -1;
}
function getExcludedItemsCount(selected) {
var count = 0;
var enum_selected_items = new Enumerator(selected);
for (; !enum_selected_items.atEnd(); enum_selected_items.moveNext()) {
var selected_item = enum_selected_items.item();
var enum_excluded_extension = new Enumerator(Script.Config["Excluded extensions"]);
for (; !enum_excluded_extension.atEnd(); enum_excluded_extension.moveNext()) {
var excluded_extension = enum_excluded_extension.item();
if (String(selected_item).endsWith(excluded_extension)) {
count ++;
break;
}
}
}
return count;
}
function handleOnDoubleClick(doubleClickData) {
if ((doubleClickData.Tab.selstats.selitems - getExcludedItemsCount(doubleClickData.Tab.selected)) > Script.Config["Threshold"] && askConfirmation(doubleClickData.tab) == 0) {
doubleClickData.cont = false; // Tells Dopus to stop processing remaining selected files
return true; // Cancel current (first) file (i.e., tells Dopus that *we* have handled this file and it doesn't have to do anything else with it)
}
else {
doubleClickData.call = false; // Tells Dopus to continue without calling this script for remaining selected files
return false; // Dopus proceeds to handle (current and) remaining selected files
}
}
function askConfirmation(Tab) {
var dlg = Tab.Dlg;
dlg.title = "Opening Multiple Items";
dlg.icon = "information";
dlg.message = Tab.selstats.selitems + " selected items are to be opened.";
dlg.buttons = "Proceed|Cancel";
dlg.defid = Script.Config["Focus button"] == 0;
return dlg.Show(); // from docs: "If a dialog has more than one button then by definition the last (right-most) button is the "cancel" button and so this will return index 0."
}