Recently I've been working more in JXL (JPEG-XL) format but I got tired of doing manual file conversions. Using the below script, I have Dopus handling that on the fly, with means to revert the conversions back and forth on an adhoc basis, as well as a way to toggle the auto-converting on and off.
Version & License
-
Version: 1.2
-
License: Free for the community to use. Modifications should be reattributed.
How it Works
This solution runs as a background Script Add-in. When auto-conversion is toggled on, it monitors your navigation using the OnAfterFolderChange event. When you open a folder, it natively queues the local JPEGs and PNGs and runs them silently through the JPEG-XL CLI.
Files are only replaced 1-for-1 if the resulting .jxl container is strictly smaller than the original. When a file is swapped, the script securely preserves the original NTFS modification and creation timestamps. It also utilizes native Directory Opus metadata tagging (Orig_JPG, Orig_PNG, and JXL_Ignore) to track origin formats and prevent infinite processing loops when you manually restore a file. Additionally, the manual conversion tools natively detect if a JXL file possesses a 32-bit alpha/transparent layer; if you try to convert it to a JPEG, the script pauses and presents an interactive dialog box with safe routing options to prevent data loss.
Toolbar Buttons
As outlined in the verbatim "Directory Opus Scripts" reference, this script automatically registers seven custom internal commands that you can assign to standard Opus toolbar buttons:
-
JXLToggle: Toggles the background folder monitoring on or off globally.
-
JXLRestore: Ad-hoc decoding. Select a .jxl file and click this to safely revert it to its exact original .jpg or .png format. It applies an ignore tag so the background monitor doesn't instantly convert it again.
-
JXLReconvert: Ad-hoc encoding. Select a .jpg or .png and click this to manually convert it back to .jxl without needing to toggle the global background monitor on.
-
JXLConvertToJPG: Copies a JXL file to a standard JPEG (preserves the original JXL file).
-
JXLConvertToPNG: Copies a JXL file to a standard PNG (preserves the original JXL file).
-
JXLFlipToJPG: Converts a JXL file to a JPEG and permanently deletes the original JXL file.
-
JXLFlipToPNG: Converts a JXL file to a PNG and permanently deletes the original JXL file.
CLI Installation Requirements
Because this script uses the official libjxl binaries, you need to install them locally before the script will work.
-
Download the latest Windows release of the command-line tools from the
libjxlrepository. -
Extract the files and place them in this exact directory structure:
C:\Program Files\jxl-x64-windows\x64-windows\bin\ -
Verify that both
cjxl.exeanddjxl.exeare present in thatbinfolder.
The Script
Save the code below as a .js file (e.g., AutoJXLPipeline.js) and place it inside your Opus scripts folder (you can type /dopusdata/Script AddIns into your location field to open it).
JavaScript
// ========================================================================
// Auto JXL Pipeline for Directory Opus
// ========================================================================
// Created by: Berkeley Goodloe
// Version: 1.2
// License: Free for the community to use. Modifications should be reattributed.
//
// Recently I've been working more in JXL (JPEG-XL) format but I got tired of
// doing manual file conversions. Using the below script, I have Dopus handling
// that on the fly, with means to revert the conversions back and forth on an
// adhoc basis, as well as a way to toggle the auto-converting on and off.
//
// DESCRIPTION:
// This script operates as a background monitor that automatically converts
// existing local JPEGs and PNGs to the JXL format when opening a folder.
// JPEGs use bit-exact container transcoding and PNGs use pixel-perfect
// compression. Files are strictly replaced 1-for-1 only if the JXL version
// is smaller. Original creation/modification timestamps are preserved natively.
//
// The script accounts for seven custom commands to be used as toolbar buttons:
// - JXLToggle: Toggles the background folder monitoring on or off globally.
// - JXLRestore: Ad-hoc decoding to safely revert a .jxl to its original format.
// - JXLReconvert: Ad-hoc encoding to manually convert a file back to .jxl.
// - JXLConvertToJPG: Copies JXL to JPEG (preserves original JXL file).
// - JXLConvertToPNG: Copies JXL to PNG (preserves original JXL file).
// - JXLFlipToJPG: Converts JXL to JPEG and deletes the original JXL file.
// - JXLFlipToPNG: Converts JXL to PNG and deletes the original JXL file.
//
// CONFIGURATION (CLI INSTALLATION):
// To align with this script, you must install the official libjxl binaries:
// 1) Download the latest Windows release of the command-line tools.
// 2) Extract the files and place them in this exact directory structure:
// C:\Program Files\jxl-x64-windows\x64-windows\bin\
// 3) Verify that both cjxl.exe and djxl.exe are present in that bin folder.
// ========================================================================
function OnInit(initData) {
initData.name = "Auto JXL Pipeline";
initData.desc = "Background conversion and multi-format manual tools.";
initData.copyright = "Pipeline";
initData.default_enable = true;
var cmdToggle = initData.AddCommand();
cmdToggle.name = "JXLToggle";
cmdToggle.method = "OnJXLToggle";
var cmdRestore = initData.AddCommand();
cmdRestore.name = "JXLRestore";
cmdRestore.method = "OnJXLRestore";
var cmdReconvert = initData.AddCommand();
cmdReconvert.name = "JXLReconvert";
cmdReconvert.method = "OnJXLReconvert";
var cmdConvJpg = initData.AddCommand();
cmdConvJpg.name = "JXLConvertToJPG";
cmdConvJpg.method = "OnJXLConvertToJPG";
var cmdConvPng = initData.AddCommand();
cmdConvPng.name = "JXLConvertToPNG";
cmdConvPng.method = "OnJXLConvertToPNG";
var cmdFlipJpg = initData.AddCommand();
cmdFlipJpg.name = "JXLFlipToJPG";
cmdFlipJpg.method = "OnJXLFlipToJPG";
var cmdFlipPng = initData.AddCommand();
cmdFlipPng.name = "JXLFlipToPNG";
cmdFlipPng.method = "OnJXLFlipToPNG";
}
function OnJXLToggle(scriptCmdData) {
var state = DOpus.Vars.Exists("JXL_AUTO_CONVERT") ? DOpus.Vars.Get("JXL_AUTO_CONVERT") : false;
DOpus.Vars.Set("JXL_AUTO_CONVERT", !state);
}
function hasTag(item, tagToFind) {
if (!item.metadata || !item.metadata.tags) return false;
var tags = item.metadata.tags;
for (var i = 0; i < tags.count; i++) {
if (tags(i).toLowerCase() === tagToFind.toLowerCase()) return true;
}
return false;
}
function formatOpusDate(d) {
function pad(n) { return n < 10 ? '0' + n : n; }
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' +
pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
}
function OnAfterFolderChange(afterFolderChangeData) {
if (!afterFolderChangeData.result) return;
if (!DOpus.Vars.Exists("JXL_AUTO_CONVERT") || !DOpus.Vars.Get("JXL_AUTO_CONVERT")) return;
var tab = afterFolderChangeData.tab;
if (tab.files.count === 0) return;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var fsUtil = DOpus.FSUtil;
var cjxlPath = "C:\\Program Files\\jxl-x64-windows\\x64-windows\\bin\\cjxl.exe";
for (var objEnum = new Enumerator(tab.files); !objEnum.atEnd(); objEnum.moveNext()) {
var item = objEnum.item();
var ext = item.ext.toLowerCase();
if (ext === ".jpg" || ext === ".jpeg" || ext === ".png") {
if (hasTag(item, "JXL_Ignore")) continue;
var originalPath = String(item.realpath);
var jxlPath = originalPath.substr(0, originalPath.length - ext.length) + ".jxl";
if (fsUtil.Exists(jxlPath)) continue;
var createDate = new Date(item.create);
var modifyDate = new Date(item.modify);
var originalSize = item.size;
var tempJxlPath = jxlPath + ".tmp";
var isJpg = (ext === ".jpg" || ext === ".jpeg");
var params = isJpg ? "-j 1" : "-q 100";
var cmdString = '"' + cjxlPath + '" ' + params + ' "' + originalPath + '" "' + tempJxlPath + '"';
shell.Run(cmdString, 0, true);
if (fsUtil.Exists(tempJxlPath)) {
var newFile = fso.GetFile(tempJxlPath);
if (newFile.Size < originalSize) {
fso.DeleteFile(originalPath);
fso.MoveFile(tempJxlPath, jxlPath);
var tsCmd = DOpus.Create.Command();
tsCmd.ClearFiles();
tsCmd.AddFile(jxlPath);
var modStr = formatOpusDate(modifyDate);
var creStr = formatOpusDate(createDate);
var origExtTag = isJpg ? "Orig_JPG" : "Orig_PNG";
tsCmd.RunCommand('SetAttr MODIFIED="' + modStr + '" CREATED="' + creStr + '" META "tags:+' + origExtTag + '"');
} else {
fso.DeleteFile(tempJxlPath);
}
}
}
}
}
function OnJXLRestore(scriptCmdData) {
var tab = scriptCmdData.func.sourcetab;
if (tab.selected_files.count === 0) return;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var fsUtil = DOpus.FSUtil;
var djxlPath = "C:\\Program Files\\jxl-x64-windows\\x64-windows\\bin\\djxl.exe";
for (var objEnum = new Enumerator(tab.selected_files); !objEnum.atEnd(); objEnum.moveNext()) {
var item = objEnum.item();
if (item.ext.toLowerCase() !== ".jxl") continue;
var targetExt = ".jpg";
if (hasTag(item, "Orig_PNG")) targetExt = ".png";
var createDate = new Date(item.create);
var modifyDate = new Date(item.modify);
var originalPath = String(item.realpath);
var restorePath = originalPath.substr(0, originalPath.length - 4) + targetExt;
var tempRestorePath = originalPath.substr(0, originalPath.length - 4) + ".tmp" + targetExt;
var cmdString = '"' + djxlPath + '" "' + originalPath + '" "' + tempRestorePath + '"';
shell.Run(cmdString, 0, true);
if (fsUtil.Exists(tempRestorePath)) {
if (fsUtil.Exists(restorePath)) fso.DeleteFile(restorePath);
fso.MoveFile(tempRestorePath, restorePath);
fso.DeleteFile(originalPath);
var tsCmd = DOpus.Create.Command();
tsCmd.ClearFiles();
tsCmd.AddFile(restorePath);
var modStr = formatOpusDate(modifyDate);
var creStr = formatOpusDate(createDate);
tsCmd.RunCommand('SetAttr MODIFIED="' + modStr + '" CREATED="' + creStr + '" META "tags:+JXL_Ignore"');
}
}
}
function OnJXLReconvert(scriptCmdData) {
var tab = scriptCmdData.func.sourcetab;
if (tab.selected_files.count === 0) return;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var fsUtil = DOpus.FSUtil;
var cjxlPath = "C:\\Program Files\\jxl-x64-windows\\x64-windows\\bin\\cjxl.exe";
for (var objEnum = new Enumerator(tab.selected_files); !objEnum.atEnd(); objEnum.moveNext()) {
var item = objEnum.item();
var ext = item.ext.toLowerCase();
if (ext !== ".jpg" && ext !== ".jpeg" && ext !== ".png") continue;
var originalPath = String(item.realpath);
var jxlPath = originalPath.substr(0, originalPath.length - ext.length) + ".jxl";
if (fsUtil.Exists(jxlPath)) continue;
var createDate = new Date(item.create);
var modifyDate = new Date(item.modify);
var originalSize = item.size;
var tempJxlPath = jxlPath + ".tmp";
var isJpg = (ext === ".jpg" || ext === ".jpeg");
var params = isJpg ? "-j 1" : "-q 100";
var cmdString = '"' + cjxlPath + '" ' + params + ' "' + originalPath + '" "' + tempJxlPath + '"';
shell.Run(cmdString, 0, true);
if (fsUtil.Exists(tempJxlPath)) {
var newFile = fso.GetFile(tempJxlPath);
if (newFile.Size < originalSize) {
fso.DeleteFile(originalPath);
fso.MoveFile(tempJxlPath, jxlPath);
var tsCmd = DOpus.Create.Command();
tsCmd.ClearFiles();
tsCmd.AddFile(jxlPath);
var modStr = formatOpusDate(modifyDate);
var creStr = formatOpusDate(createDate);
var origExtTag = isJpg ? "Orig_JPG" : "Orig_PNG";
tsCmd.RunCommand('SetAttr MODIFIED="' + modStr + '" CREATED="' + creStr + '" META "tags:+' + origExtTag + '"');
} else {
fso.DeleteFile(tempJxlPath);
}
}
}
}
// ------------------------------------------------------------------------
// ROUTING COMMANDS FOR EXPLICIT CONVERSIONS
// ------------------------------------------------------------------------
function OnJXLConvertToJPG(scriptCmdData) { ProcessJXLManual(scriptCmdData, ".jpg", false); }
function OnJXLConvertToPNG(scriptCmdData) { ProcessJXLManual(scriptCmdData, ".png", false); }
function OnJXLFlipToJPG(scriptCmdData) { ProcessJXLManual(scriptCmdData, ".jpg", true); }
function OnJXLFlipToPNG(scriptCmdData) { ProcessJXLManual(scriptCmdData, ".png", true); }
// ------------------------------------------------------------------------
// CENTRAL HELPER: Processes explicit JXL -> Image commands
// ------------------------------------------------------------------------
function ProcessJXLManual(scriptCmdData, targetFormat, deleteOriginal) {
var tab = scriptCmdData.func.sourcetab;
if (tab.selected_files.count === 0) return;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var fsUtil = DOpus.FSUtil;
var djxlPath = "C:\\Program Files\\jxl-x64-windows\\x64-windows\\bin\\djxl.exe";
var skipAlphaPrompt = false;
var alphaAction = "";
for (var objEnum = new Enumerator(tab.selected_files); !objEnum.atEnd(); objEnum.moveNext()) {
var item = objEnum.item();
if (item.ext.toLowerCase() !== ".jxl") continue;
var targetExt = targetFormat;
// Depth > 24 indicates 32-bit (RGBA) or 64-bit color depth (contains Alpha)
if (targetExt === ".jpg") {
var hasAlpha = (item.metadata && item.metadata.image && item.metadata.image.depth > 24);
if (hasAlpha) {
if (!skipAlphaPrompt) {
var dlg = scriptCmdData.func.Dlg;
dlg.title = "Alpha Channel Detected";
dlg.message = "The image '" + item.name + "' has an alpha/transparent layer. Converting to JPEG will strip this layer.\n\nAre you sure you want to proceed?";
if (tab.selected_files.count === 1) {
dlg.buttons = "Yes|PNG instead|Cancel";
var result = dlg.Show();
if (result === 0) break;
if (result === 1) targetExt = ".jpg";
if (result === 2) targetExt = ".png";
} else {
dlg.buttons = "Yes|Yes to all|PNG instead|PNG only for images with alpha channels|Cancel";
var result = dlg.Show();
if (result === 0) break;
if (result === 1) targetExt = ".jpg";
if (result === 2) { targetExt = ".jpg"; skipAlphaPrompt = true; alphaAction = "jpg"; }
if (result === 3) targetExt = ".png";
if (result === 4) { targetExt = ".png"; skipAlphaPrompt = true; alphaAction = "png"; }
}
} else {
targetExt = (alphaAction === "png") ? ".png" : ".jpg";
}
}
}
var createDate = new Date(item.create);
var modifyDate = new Date(item.modify);
var originalPath = String(item.realpath);
var restorePath = originalPath.substr(0, originalPath.length - 4) + targetExt;
var tempRestorePath = originalPath.substr(0, originalPath.length - 4) + ".tmp" + targetExt;
var cmdString = '"' + djxlPath + '" "' + originalPath + '" "' + tempRestorePath + '"';
shell.Run(cmdString, 0, true);
if (fsUtil.Exists(tempRestorePath)) {
if (fsUtil.Exists(restorePath)) fso.DeleteFile(restorePath);
fso.MoveFile(tempRestorePath, restorePath);
// Evaluates the boolean flag dictated by the firing button
if (deleteOriginal) {
fso.DeleteFile(originalPath);
}
var tsCmd = DOpus.Create.Command();
tsCmd.ClearFiles();
tsCmd.AddFile(restorePath);
var modStr = formatOpusDate(modifyDate);
var creStr = formatOpusDate(createDate);
tsCmd.RunCommand('SetAttr MODIFIED="' + modStr + '" CREATED="' + creStr + '" META "tags:+JXL_Ignore"');
}
}
}