I was using the very first one made available above by pctechtv.
Alright, will change the line in the script.
EDIT: Changed the line in the script. It's fixed!
Here is the final script for those that stumbles upon this thread.
/* eslint quotes: ['error', 'single'] */
/* eslint-disable no-inner-declarations */
/* global DOpus Script */
/* Demo script by cyilmax and enhanced by pctechtv and tbone on Dopus forums */
/* v1.0 Initial release by pctechtv */
/* v1.1 Fix auto-rename when path has one or multiple spaces (by tbone) */
///<reference path="./_DOpusDefinitions.d.ts" />
var DEBUG = true;
function $dbg(/**@type {any}*/str) { if (DEBUG) DOpus.output(str); }
function OnInit(/** @type {DOpusScriptInitData} */ initData) { // eslint-disable-line no-unused-vars
initData.name = 'fsUtil.WatchChanges demo';
initData.desc = 'fsUtil.WatchChanges demo';
initData.version = '1.1';
initData.copyright = '© cy - Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)';
initData.default_enable = true;
initData.group = 'cy';
initData.desc = 'This script adds 2 commands: cuWatchFolder & cuUnwatchFolder with the same signature PATH/O\n.'
+ 'Use cuWatchFolder PATH Y:\\ or cuUnwatchFolder PATH Y:\\';
var cmd;
cmd = initData.addCommand();
cmd.name = 'cuWatchFolder';
cmd.method = 'cuWatchFolder';
cmd.desc = '';
cmd.label = 'cuWatchFolder';
cmd.template= 'PATH/O';
cmd.icon = 'folder';
cmd = initData.addCommand();
cmd.name = 'cuUnwatchFolder';
cmd.method = 'cuUnwatchFolder';
cmd.desc = '';
cmd.label = 'cuUnwatchFolder';
cmd.template= 'PATH/O';
cmd.icon = 'folder';
}
function OnFilesystemChange(/** @type {DOpusFilesystemChangeData} */ filesyschangedata) { // eslint-disable-line no-unused-vars
$dbg('OnFilesystemChange called');
/** @type {DOpusMap} */
var cache = Script.vars.get('cache');
var path = '';
if (cache.exists(filesyschangedata.id)) {
path = cache.get(filesyschangedata.id);
$dbg('change for watch id: ' + filesyschangedata.id + ', path: ' + path);
//DOpus.Output(path)
//
// DO SOMETHING HERE
//DOpus.OUtput("Directory Opus is watching now")
autoNumImgfiles(path)
//
} else {
$dbg('got a change event but cannot find id: ' + filesyschangedata.id);
}
}
function cuWatchFolder(/** @type {DOpusScriptCommandData} */ cmdData) { // eslint-disable-line no-unused-vars
var args = cmdData.func.args;
if (!args.got_arg.PATH) {
return;
}
var path = '' + args.PATH;
var uniqueid = getUniqueID(path);
if (!Script.vars.exists('cache')) {
Script.vars.set('cache', DOpus.create().map());
}
/** @type {DOpusMap} */
var cache = Script.vars.get('cache');
if (cache.exists(uniqueid)) {
$dbg('this folder is already being watched by same id: ' + uniqueid + ', path: ' + path);
return;
}
var errcode = DOpus.fsUtil().watchChanges(uniqueid, path, 'fdrs');
if (errcode) {
$dbg('an error occurred, aborting - error code: ' + errcode);
return;
}
$dbg('watching path: ' + path + ', id: ' + uniqueid);
cache.set(uniqueid, path);
Script.vars.set('cache', cache);
}
function cuUnwatchFolder(/** @type {DOpusScriptCommandData} */ cmdData) { // eslint-disable-line no-unused-vars
var args = cmdData.func.args;
if (!args.got_arg.PATH) {
return;
}
var path = '' + args.PATH;
var uniqueid = getUniqueID(path);
/** @type {DOpusMap} */
var cache = Script.vars.get('cache');
if (!cache.exists(uniqueid)) {
$dbg('this folder is not being being watched, path: ' + path);
return;
}
$dbg('unwatching path: ' + path + ', id: ' + uniqueid);
DOpus.fsUtil().cancelWatchChanges(uniqueid);
cache.erase(uniqueid);
Script.vars.set('cache', cache);
}
function getUniqueID(/** @type {string} */ str) {
var blob = DOpus.create().blob();
blob.copyFrom(str);
return '' + DOpus.fsUtil().hash(blob, 'md5');
}
function autoNumImgfiles(path){
var cmd = DOpus.Create.command;
cmd.deselect = false;
//if (tab.all.count == 0) return;
var re = /^(\d+)$/;
var ex = /bmp|gif|jpg|jpeg|png|webp/
var maxNum = 0;
cmd.ClearFiles();
var folderEnum = DOpus.FSUtil.ReadDir(path);
while (!folderEnum.complete) {
var item = folderEnum.Next();
var tmp = item.name_stem.match(re);
var tpm = item.ext.match(ex);
//DOpus.Output(tmp[1])
if (tpm) {
if (tmp) {
var num = Number(tmp[1]);
if (num > maxNum) maxNum = num;
} else {
//cmd.AddFile(item);
//DOpus.Output(item)
var mxx = ++maxNum;
var cmdLine = 'Rename IGNOREEXT "' + item + '" TO "' + mxx + '"'
cmd.RunCommand(cmdLine);
}
}
}
}
I did test. I talked about it in a previous post (#28). The first one was C:\Users\Lebon14\Desktop\script and the second was F:\script. Both worked. Then stopped working when I tried moving more towards the folder I wanted to watch. By then, there were spaces in the file path.
EDIT 2: Before I forget, a big thank you to everyone involved. <3