Sending text into 'rename' file box in Explorer Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Sending text into 'rename' file box in Explorer

Post by Lem2001 » 14 Oct 2021, 17:10

I have a collection of different strings of text that I use as part of my file naming scheme. At the moment I have these strings saved in a text document, and whenever I want to include one of the strings in the name of a file or folder, I have to copy the desired string from the text file and then paste it into the rename box under the file/folder icon in Explorer. This is cumbersome and time consuming.

I would instead like to be able to press a hotkey when Explorer is in rename mode (for example after pressing F2) and have AutoHotkey send text into the rename box for the currently selected file or folder.

Setting up a hotkey to Send text is easy, but I don't want the hotkey to be always active whenever Explorer has focus; I'd like it to only work if an Explorer icon is in rename mode (i.e. the filename under the icon is focused and editable), but I don't know how to detect this state or how to specify it in code. I don't want the hotkey to send strings to Explorer when a file or folder item is not currently in the process of being renamed.

Is this possible in AutoHotkey?

evilmanimani
Posts: 29
Joined: 24 Jun 2020, 16:42

Re: Sending text into 'rename' file box in Explorer

Post by evilmanimani » 14 Oct 2021, 17:46

You might be able to use Acc.ahk to scan for it, but that will probably be fairly involved, for an alternative approach though, I see there's a function available to get the full path of the currently selected file path here:

https://www.autohotkey.com/board/topic/60985-get-paths-of-selected-items-in-an-explorer-window/

You could then use the retrieved path in combination with FileMove in order to rename the file directly, with your clipboard contents for instance. You could make it a multiple key hotkey to reduce the chances of hitting it accidentally, would that work?

Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: Sending text into 'rename' file box in Explorer

Post by Lem2001 » 15 Oct 2021, 17:42

Thank you for your reply and suggestion. Unfortunately this will not work for me. The whole point of me doing this was to avoid using the clipboard (which clutters up my clipboard manager's history with endless junk entries because I need to do this so often) and that is which is why I specified using the Send command) in my original post.

Also, the position in the filename where any one of the strings will be entered, varies on a case-by-case basis; so it would be impossible to create pre-made rules to cover every eventuality.

That's why I wanted to just right-click > rename (or press F2) and then place the cursor where I want the text to be entered, and then I could just press the appropriate hotkey for the particular text that I wanted to be entered at the cursor point.

evilmanimani
Posts: 29
Joined: 24 Jun 2020, 16:42

Re: Sending text into 'rename' file box in Explorer

Post by evilmanimani » 15 Oct 2021, 18:30

From the clipboard is just an example, you could have the strings assigned to different hotkeys or in a GUI as well, the clipboard doesn't need to be in the picture at all. How many different strings are there?

Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: Sending text into 'rename' file box in Explorer

Post by Lem2001 » 18 Oct 2021, 17:12

The number of strings varies, but at any moment in time I am usually regularly using 4 or 5 of them, but any one of them can get placed at a different point in the filename depending on which file is being amended (and a variety of other file-content related refactors).

So the main issue that I am trying to address is how to get the sent text to paste into the 'rename' box in Explorer.

Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: Sending text into 'rename' file box in Explorer  Topic is solved

Post by Lem2001 » 18 Oct 2021, 19:51

I am such an idiot!

I have answered my own question, and it was SO easy.

I don't know why I assumed that detecting the state of an Explorer rename box would be so complicated. I just assumed that getting a ClassNN value for it would not be straight-forward because it's a dynamic control that only exists in rename mode (rather than being a standard always-visible static control like a button or text input box).

However, I decided just to see what Window Spy revealed when a file in Explorer was in 'rename' mode (with an editable filename box under the icon), and it turns out that it's just an ordinary Edit2 control (separate from its non-rename state, and also separate from the other edit control for folder paths at the top of the Explorer window).

So, it's simply a matter of using WinActive to restrict the hotkey to when Explorer has focus, and then using ControlGetFocus to check for Edit2. When both of those conditions are met then my hotkey to insert a text string is activated, otherwise it's not (which is to prevent accidental presses of the hotkey from sending text strings to random places).

Post Reply

Return to “Ask for Help (v1)”