Rename selected file, preserve activate inline rename at specific position

Hello.

I am try to set a hotkey command which renames the selected file by maintaining the existing name but adding new name elements into the filename and then set on inline editing with the cursor at a specific position so that I can further manually add filename elements to the final outcome.

Here's what I have so far (hotkey is already set):

 rename CASE=lower
 rename PRESET="Invoices and Payments Files"

Is there a command I can additionally set so that after these first two commands are run, the file is put into inline renam mode with the cursor at a specific position other than "home" or "end"?

Which position do you want?

26th, from the left.

Literally the 26th character every time, no matter how long or short the filename is?

Or do you want to start on the file extension?

Yes. The idea is to keep the existing filename, insert a predefined template of filename text at the beginning, and move the cursor to the 26th letter-position so that I can easily manually enter more filename components. :slight_smile:

rename inline=endstem will begin inline-renaming with the cursor just before the . in the extension.

Thanks Leo but I'm aware of that argument and it's not what I need because I want the cursor to land in a certain spot within the new filename template, not at the end of the stem, nor the beginning. Possible?

I don’t think that’s possible, sorry. Only at the positions that the various arguments to that command let you choose.

You could instead show a dialog prompting for part of the name to add after the fixed part, or something similar.

I understand. Thanks for your time, Leo. I'll consider my options. Anyway, it's not mission critical - just a convenience I was hoping for. :slight_smile:

This seems to work.

// https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var wsh = new ActiveXObject('WScript.Shell');
    cmd.deselect = false;

    cmd.RunCommand('Rename CASE=lower');
    cmd.RunCommand('Rename PRESET="Invoices and Payments Files"');
    cmd.RunCommand('Rename INLINE=home');

    // In case there are timing problems
    // DOpus.Delay(1000);

    for (var i = 0; i < 26; ++i) {
        wsh.SendKeys('{RIGHT}');
    }
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>41349</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var wsh = new ActiveXObject(&apos;WScript.Shell&apos;);</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    cmd.RunCommand(&apos;Rename CASE=lower&apos;);</instruction>
		<instruction>    cmd.RunCommand(&apos;Rename PRESET=&quot;Invoices and Payments Files&quot;&apos;);</instruction>
		<instruction>    cmd.RunCommand(&apos;Rename INLINE=home&apos;);</instruction>
		<instruction />
		<instruction>    // In case there are timing problems</instruction>
		<instruction>    // DOpus.Delay(1000);</instruction>
		<instruction />
		<instruction>    for (var i = 0; i &lt; 26; ++i) {</instruction>
		<instruction>        wsh.SendKeys(&apos;{RIGHT}&apos;);</instruction>
		<instruction>    }</instruction>
		<instruction>}</instruction>
	</function>
</button>

Thanks guys. I have inserted the code provided by Ixp and tried running it using my hotkey, but I get this:

30-May-2022 07:06 Error at line 1, position 29
30-May-2022 07:06 function OnClick(clickData) {
30-May-2022 07:06 ^
30-May-2022 07:06 Invalid character (0x800a0408)
30-May-2022 07:06 Parse error - script aborted
30-May-2022 07:09 Error at line 1, position 29
30-May-2022 07:09 function OnClick(clickData) {
30-May-2022 07:09 ^
30-May-2022 07:09 Invalid character (0x800a0408)
30-May-2022 07:09 Parse error - script aborted

I presume that I do not have to actually "click" a button I set up and can just configure a hotkey. Any suggestions?

Did you switch to VBScript?

I did. Yes.

It'll need to be set to JScript I think.

Yes, Jon, you're right - JScript did the trick. It works nicely. Thank you.
Thank Leo.
And thanks a bunch Ixp.

Hi again, everyone. Sorry, but I've just realised there's a small problem with the script and if you can help me it will be greatly appreciated.

The line: cmd.RunCommand('Rename CASE=lower');

Although it runs before the Rename PRESET, when the PRESET line runs, the CASE=lower change to the existing filename is lost. Everything else works perfectly but then I need to manually change the segment of the filename which was supposed to have been made lowercase.

Can you help?

Todd

Swap the two lines. Merging them will probably work as well. Or edit the preset.

Thanks for replying, Ixp. I've tried swapping them but that has not worked. As for merging, can you show me the code for that? I'm not too good at this stuff. Sorry.

This should work

cmd.RunCommand('Rename PRESET="Invoices and Payments Files" CASE=lower');

Thanks Ixp. That does the trick.