Userscript stopped working when moving to Windows 11

I have a userscript which I have used for years which saves a copy of my file to a backup folder with a date and time added every time the file is updated and saved, this has worked fine up to now. I have just moved to windows 11 and it has suddenly stopped working and just gives an error.

I have tracked down the problem to the lines of code that check if the backup folder exists and if not creates it,

if (!osPath.exists(backup_fld)) {
os.mkdir(backup_fld);
ko.statusBar.AddMessage('Create folder '+backup_fld, ‘editor’, 5000, true);
}

if I remove that part, the script works and happily saves a copy of the file, this is OK with existing projects as the folders exist, but it would be nice to have that check/create back for new projects.

Anyone any idea why this should suddenly stop working under windows 11 when is was working under windows 10 using the same version of Komodo 12.0.1 build 91869.

As far as I can see the check for the existence of the folder incorrectly returns true so it tries to create a folder that already exists and falls over.

Full script below, this originally came from a post on this board way back.
Thanks
John

var os = Components.classes["@activestate.com/koOs;1"].getService(Components.interfaces.koIOs);
var basename = ko.views.manager.currentView.koDoc.file.baseName;
var curdir = ko.views.manager.currentView.koDoc.file.dirName;
var scimoz = ko.views.manager.currentView.scimoz;
var content = scimoz.text;
var date = new Date();
var Year = date.getFullYear();
var Month = date.getMonth();
var Day = date.getDate();
var Hour = date.getHours();
var Minute = date.getMinutes();
var Second = date.getSeconds();
if(Month<10) Month = “0” + Month;
if(Day<10) Day = “0” + Day;
if(Hour<10) Hour = “0” + Hour;
if(Minute<10) Minute = “0” + Minute;
if(Second<10) Second = “0” + Second;
var timestamp = Year+"-"+Month+"-"+Day+"-"+Hour+"-"+Minute+"-"+Second+"-";
var backup_fld = curdir+"_bak/";
var backup =backup_fld+timestamp+basename+".bak";

if (!osPath.exists(backup_fld)) {
os.mkdir(backup_fld);
ko.statusBar.AddMessage('Create folder '+backup_fld, ‘editor’, 5000, true);
}
os.writefile(backup, content);
ko.statusBar.AddMessage('Save '+basename+" to "+backup_fld, ‘editor’, 5000, true);

Should this be os.path.exists?

Many thanks Caryh, that cured it, wonder why the old script worked well so long but only threw an error when I moved to Win 11.

Honestly, I’m not sure! I could see this happening if you were accessing an undefine attribute of the object which would evaluate to false but calling an undefined function should have caused the script to explode with a TypeError: osPath.exist is not a function.

Do you possibly have osPath defined globally some how from a script that runs at Komodo start up and is not what you were expecting here? You could try opening the JS Console in Komodo and see if osPath is defined and what it is, if it is: View menu > Tabs & Sidebars > Console

Maybe that is the issue, because the machine was getting sluggish and I had a few issues with Komodo, including it freezing from time to time, I did a clean install of Win 11 rather than just an upgrade and totally reinstalled Komodo 12 which is currently working in default mode with no additions or modifications other than that script, so that could have cleaned out anything that could have been in the old install and may have been the reason for the script working. But I looked in console and it is totally blank.
Many thanks for your help.

No problem at all, @johnw.

  • Carey