In Macro Preferences, in tab Triggers you can set trigger “After file save” to call your macro when you save your file (Captain obvious).
Also, I think “komodo.koDoc” is not right. Try to use ko.views.manager.currentView.koDoc or insert
All of this not working
I’m almost finished my macro. Today I’m upload it.
But I don’t know, how to create file from macro.
In koIOs I can found mkdir, but can’t found “touch” or something to create file.
var os = Components.classes["@activestate.com/koOs;1"].getService(Components.interfaces.koIOs);
My bad, works normal.
Created!!!
var osPath = Components.classes["@activestate.com/koOsPath;1"].getService(Components.interfaces.koIOsPath);
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+basename+timestamp;
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);
Hmm, your macro uses @mozilla.org components… In Komodo sources I don’t find this and use only Komodo components
And your macro just copy:
My macro. (It’s not bad, but I think create macros with same functions is break “up to date” for macro). 2. File that you want to backup. But what happens if you don’t have permissions to copy file that you want to backup? I think copy content of file (because to copy content you just must have permissions to read file) is more logical than copy file. Or not?
My bad. To copy files just need have permissions to read files. Sorry.