Help with button to rename from clipboard text

Is it possible to rename with clipboard text, for a button, please.

The Rename dialog has clipboard options built in, in the button/menu near the bottom.

You can also use {clip} to insert the clipboard text into any command, for use in buttons and hotkeys.

If you need help setting up a button, please give more detail on what you want it to do.

highlight file - press button (renames instantly, no dialog, with text from clipboard) - hoping it won't crash if i try and paste an exe or an image lol. Please.

Rename INLINE={clip},single
would this work ?

-It brings up the dialog

Probably not exactly what you want, but what you asked for:

@nodeselect 
Rename TO={clip}
1 Like

That works - too well - its deleting the file extension as well ;

@nodeselect 
Rename TO={clip}{file|ext}

This works with file extension. Many thanks for helping.

That may not work with more than one file(type) selected.

This will preserve the extensions of all files, and also covers the clipboard text having a space in it:

Rename TO="{clip}" IGNOREEXT

(Note that you can also just push F2, Ctrl-V to do similar when there's only one file.)

I'm using a button with these commands:

@NoDeselect
Rename TO="{clip}__{file}" IGNOREEXT

Is there a way to cause it to take no action if the clipboard doesn't contain text?

In Opus 12, you can do it via JScript:

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	cmd.deselect = false;
	if (DOpus.GetClipFormat() != "text")
		return;
	cmd.RunCommand('Rename TO="{clip}__{file}"');
}

(In Opus 13, there's probably an easier way to do it using the Evaluator.)

I took out the IGNOREEXT as I doubt you want that in combination with {file} in the name. It was causing the file extension to be repeated at the end.

1 Like

The button could start with a line like

@disableif:=Clip()==""
2 Likes

Thank you both for the brilliant solutions.

I'm trying to expand Leo's JScript so I can change the logic based on the clipboard's contents. How can I use the clipboard text data in JScript? I tried:

var clipTxt = '{clip}'+'';

but that sets clipTxt to the literal "{clip}" rather than to the clip's contents.

Use the DOpus.GetClip() function.

1 Like