# Rename selected file, preserve activate inline rename at specific position

**URL:** <https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349>\
**Category:** Help & Support\
**Created:** [May 28, 2022, 9:58pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349 "2022-05-28T21:58:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 28, 2022, 9:58pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/1 "2022-05-28T21:58:40Z")

</div>

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"?

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [May 29, 2022, 3:26am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/2 "2022-05-29T03:26:31Z")

</div>

Which position do you want?

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 29, 2022, 4:33am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/3 "2022-05-29T04:33:37Z")

</div>

26th, from the left.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [May 29, 2022, 9:54am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/4 "2022-05-29T09:54:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 29, 2022, 10:53am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/5 "2022-05-29T10:53:27Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [May 29, 2022, 1:30pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/6 "2022-05-29T13:30:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 29, 2022, 2:49pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/7 "2022-05-29T14:49:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [May 29, 2022, 4:10pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/8 "2022-05-29T16:10:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 29, 2022, 4:36pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/9 "2022-05-29T16:36:29Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [May 29, 2022, 6:38pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/10 "2022-05-29T18:38:44Z")

</div>

This seems to work.

```javascript
// 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**
>
> ```plaintext
> <?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>
> 
> ```

* * *

> [@How to use buttons and scripts from this forum](https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546):
>
> This post explains how to add buttons to toolbars and menus, and also applies to raw commands for things like standalone hotkeys. For how to use Script Add-Ins, please scroll down to the post below this one. See Also: The manual has more detail in…

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 30, 2022, 3:10am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/11 "2022-05-30T03:10:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [May 30, 2022, 5:32am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/12 "2022-05-30T05:32:57Z")

</div>

Did you switch to VBScript?

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 30, 2022, 5:56am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/13 "2022-05-30T05:56:02Z")

</div>

I did. Yes.

---

<div class="post-metadata">

**Author:** ![Jon](https://resource.dopus.com/user_avatar/resource.dopus.com/jon/32/12713_2.png) [@Jon](https://resource.dopus.com/u/Jon)\
**Post date:** [May 30, 2022, 6:00am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/14 "2022-05-30T06:00:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [May 30, 2022, 6:27am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/15 "2022-05-30T06:27:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [June 14, 2022, 2:12pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/16 "2022-06-14T14:12:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [June 14, 2022, 2:24pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/17 "2022-06-14T14:24:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [June 14, 2022, 3:07pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/18 "2022-06-14T15:07:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [June 14, 2022, 3:35pm UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/19 "2022-06-14T15:35:05Z")

</div>

This should work

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

```

---

<div class="post-metadata">

**Author:** ![toddcarson](https://resource.dopus.com/user_avatar/resource.dopus.com/toddcarson/32/71932_2.png) [@toddcarson](https://resource.dopus.com/u/toddcarson)\
**Post date:** [June 15, 2022, 2:36am UTC](https://resource.dopus.com/t/rename-selected-file-preserve-activate-inline-rename-at-specific-position/41349/20 "2022-06-15T02:36:06Z")

</div>

Thanks Ixp. That does the trick.
