I have a macro that uses javascript to try to increment a variable and add it to a copied name. Another macro sets the variable "FMScriptNameStart" So I have a bunch of scripts in FileMaker (not important) that I want to prefix correctly. I will set something like 10.01 in "FMScriptNameStart" and I will be on a script named something like "My First Script" and I want to result to be "10.01 My First Script" and then move down one script. I then can hit it again and get something like "10.02 My Second Script" when the next one was named "My Second Script"
Right now it is working except it is not incrementing. What am I missing?
In case you cant read the code or if you want to fix it I will include the javascript here:
//--- GET A REFERENCE TO THE KM ENGINE ---
var kme = Application("Keyboard Maestro Engine");
//--- GET A KM VARIABLE ---
var scriptStart = kme.getvariable('FMScriptNameStart');
var scriptName = kme.getvariable('scriptName');
//--- SET A KM VARIABLE ---
// - Using explicit text
//kme.setvariable('My Other KM Var', { to: "Set by JXA" });
// - Using a JavaScript Variable
var numbs = scriptStart.split(".");
if ( numbs.includes(3) ){
// Set each piece of the xx.xx.xx to have zero padding
result = numbs[0] + "." + numbs[1] + "." + numbs[2] + "." + (parseInt(numbs[3]) + 1).padStart(2, '0');
}else if( numbs.includes(2) ){
result = numbs[0] + "." + numbs[1] + "." + (parseInt(numbs[2]) + 1).padStart(2, '0');
}else if( numbs.includes(1) ){
result = numbs[0] + "." + (parseInt(numbs[1]) + 1).padStart(2, '0');
}else{
result = (parseInt(numbs[0]) + "." + "01" );
}
scriptName = result + " " + scriptName;
kme.setvariable('scriptName', { to: scriptName });