Conditional Rename Button

I currently have a button that renames a file to suffix a "-bkup" at the end of it.

Looks like:

	Rename PATTERN="*.*" TO="*-bkup.*"

Often times I want to remove that "-bkup" if i no longer want it.

Can i create a single button that will add the "-bkup" if it doesn't exist and remove it if it does?

I want it to have a toggle effect. I can't use the right click because I have that mapped as something else.

Thanks for any advice.

Give this a try

@nodeselect 
Rename PATTERN=*.* TO=*.*

@script jscript 
function OnGetNewName(getNewNameData) {
    var tmpName = getNewNameData.newname_stem;
    var tmpExt = getNewNameData.newname_ext;

    if (tmpName.slice(-5) == '-bkup') {
        tmpName = tmpName.substr(0, tmpName.length - 5);
    } else {
        tmpName += '-bkup';
    }
    return tmpName + tmpExt;
}
2 Likes

lxp this works really well! Thank you!

Just an oddity that may not be a problem with the script:

If i toggle multiple times, occasionally the active file deselects.

I can sometimes click 10 times in a row with no problems. On the 11th click (for example) the filename will deselect.

Nothing else is gong on. It just randomly seems to not want to keep the @nodeselect.

Is that a bug perhaps with the @nodeselect?

I'm on 12.12 build 6961.

Any suggestions?