I want to figure out how to create a custom Context Menu item to convert a string of selected text to uppercase (or lowercase) using Regedit and Powershell.
I am interested in this being a non-program-specific function (not just in Word, or just in any particular program, but just any selected text in any text editor).
I am also interested in this as a fun challenge to solve....and while I appreciate constructive input, please no comments or answers that say nothing more than "you can't do that" (unless you can fully back it up with programming limitation data), Also I'm not interested in 3rd party software solutions (AutoHotKey being the only exception).
I tried this method and it comes close:
Created a Powershell Script that reads:
Add-Type -AssemblyName System.Windows.Forms $clipboardText = [System.Windows.Forms.Clipboard]::GetText() if ($clipboardText) {
$uppercaseText = $clipboardText.ToUpper()
[System.Windows.Forms.Clipboard]::SetText($uppercaseText) }
and saved this file to disk.
Then, in the registry, at HKEY_CLASSES_ROOT\*\shell created a key "ToUppercase" and under this created a key called "command" and then in the (default) field added:
powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -File "C:\ToUpperCase.ps1"
To test, I copy some text. Then, I found that the only way to get the new Context Menu Item to appear is to right click on literally any file in File Explorer directory list. Then it runs the Powershell script and the previously copied text is now on the clipboard, converted to UPPERCASE and can be pasted wherever.
I just want the new Context Menu Item to show up when I right-click in a blank area of, say, Notepad ... not having to open a File Explorer window and right-clicking on a file to get it to show up.
So the only thing left to figure out is how to get it to show up on the context menu that appears when you right-click on a blank area of a text editor. Right now, what shows up is Undo, Cut, Copy, Paste, Select All, Open IME, Right to Left Reading Order, Etc....
Any help appreciated.
What happens when you right-click into the Window of any text processing app is determined by the app. No way to intercept, modify or extend this on a standard user/programmer level. It might be possible using some kind of kernel level injection, but that's way out of my scope.
What you can do is using a session level hotkey. So, you need an invisible background app which registers this hotkey and when the hotkey is typed your invisible background app may show a popup menu at the current position of the cursor and offer functions which may interact with the clipboard. I have a private tool for my own purposes (named zClipMan) which exactly uses this approach, so I can safely confirm it's technically possible.
Nevertheless, I doubt it is possible using PowerShell. Showing such popup menu virtually out of nothing is not rocket science but requires some coding on Win32 API level which isn't easily in scope for PowerShell. My own tool is written in C++.