Hook paste when editing file names to substitute illegal symbols

I'd like to be able to intercept the paste command when editing a file name to allow replacing illegal symbols (like ") with a valid alternative (like ).
I see there is Ctrl-V command for regular paste of files/clipboard content to a file, but it doesn't seem to work when I'm renaming a file name.

So is there a way to write custom script that would receive as input clipboard text and send as output another text when renaming a file?

Alternatively would be nice to have a native DOpus option that would allow replacing illegal file name symbols with user given alternatives

There are some old suggestions Can DOpus automatically handle/change illegal characters? - #18 by robertcollier4 with AHK workarounds, but then for those there is no way to activate only for inline renames so that the you can use the same key combo and forget about the issue.

Tangentially: would be cool if AHK scripts could read whether inline rename mode is active or not...

FYI potential default replacements if DOpus were to add this feature

*:"\|<>/?^
∗꞉”⧵¦‹›⧸⸮ˆ
(though for quotes a proper “” pairng would be better)

P.S.
An evaluator function that auto-pairs "" to “”, odd " becomes and updates cursor position to hopefully match the original paste (and removes carriage returns and newlines)

<?xml version="1.0"?>
<regexsel key="ctrl+V" name="Paste clipboard, replacing illegal filename symbols with legal unicode alternatives">
	<eval>clip = Clip();
clip = Replace(clip,&quot;*&quot;,&quot;∗&quot;);
clip = Replace(clip,&quot;:&quot;,&quot;꞉&quot;);
clip = Replace(clip,&quot;\&quot;,&quot;⧵&quot;);
clip = Replace(clip,&quot;|&quot;,&quot;¦&quot;);
clip = Replace(clip,&quot;&lt;&quot;,&quot;‹&quot;);
clip = Replace(clip,&quot;&gt;&quot;,&quot;›&quot;);
clip = Replace(clip,&quot;/&quot;,&quot;⁄&quot;); // ⁄=fraction slash; ⧸=big solidus
clip = Replace(clip,&quot;?&quot;,&quot;⸮&quot;);
clip = Replace(clip,&quot;^&quot;,&quot;ˆ&quot;);
clip = RegExS(clip,&quot;\r\n&quot;,&quot;&quot;);
clip = RegExS(clip,&quot;\n&quot;,&quot;&quot;);

//output(Concat(2,clip,&quot;¦&quot;));

cnt_quote = Count(clip, &quot;&quot;&quot;&quot;);
cqh = Ceil(cnt_quote / 2.0); // round up to make middle “
for (i = 1; i &lt;= cnt_quote; i++) {
  clip = Replace(clip,&quot;&quot;&quot;&quot;,(i &lt;= cqh)?&quot;“&quot;:&quot;”&quot;,,1);
}
//clip = Replace(clip,&quot;&quot;&quot;&quot;,&quot;”&quot;);
selstart = selstart + len(clip);
selend = selstart;

return valleft + clip + valright
</eval>
</regexsel>

You can edit/override inline-rename hotkeys here:

  • Preferences / File Operations / Renaming Files / Control Keys

I've not tried that to override the built-in Ctrl+V behavior, but that'd be the place to do it.

You can use the Evaluator Clip() function to get the clipboard content, then filter it using the other functions as you wish.

1 Like

Ctrl-V is reserved, so can't change it :frowning:

Ah, sorry about that, I forgot it wouldn't let you override that key.

You could make an alternative key to paste with different rules to normal.

Making an alternative would break years of muscle memory for Ctrl+V, so would be rather undesirable. I'd like to override the default behavior once and then forget about it :slight_smile:

We'll allow Ctrl-C/X/V to be overridden in the next update.

2 Likes