This was a good list, just for fun i had a bash at #1 (an excuse to learn as much as anything...):
prepend-selection.ps1:
$before = Get-Clipboard
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Windows.Forms.SendKeys]::SendWait("%({TAB})") # when launched, a powershell.exe opens and steals focus, this alt+tab takes focus back to the app that has the text selection
[System.Windows.Forms.SendKeys]::SendWait("^(c)") # ctrl+c
$after = Get-Clipboard
Set-Clipboard -Value ($after + $before)
Now for the impossible bit - perform this action on ctrl+[ keypress... I created a new shortcut on the desktop (in the start menu would also work) with a target of:
And the "start in" was set to the dir containing prepend-selection.ps1
Lastly the "shortcut key" of the shortcut was set to CTRL+SHIFT+[ -- i couldn't use CTRL+[
... and it works. Open an app like notepad, put something on the clipboard, select some other text then ctrl+shift+[ with notepad still having the focus and... wait far too long but then eventually powershell.exe opens and i have the selected value prepended to my clipboard.
0 out of 10. Would not do again, AHK definitely beats powershell for this use case :-)
For #2 i know how to do that already - create a Shell.Application com object and then cycle through the window list and set width / height / top / left to suit.
For #3 i didn't try it but i wonder if there's a mechanism where i can insert a function to be called back into window's message processing loop. Like how i imagine AHK does it. This is just a thought, i'd just use AHK before i actually tried this.
For #4 this suffers the same issue as #1 with the "define a keypress" limitation but otherwise it's just an exec + focus window + send keys (likely with some hacky sleeps in between).
The code you wrote will do but in AHK its 1 liner, ets 0 memory and CPU. You can also compile it into exe or use portable AHK. It can stay in tray with another line.
prepend-selection.ps1:
Now for the impossible bit - perform this action on ctrl+[ keypress... I created a new shortcut on the desktop (in the start menu would also work) with a target of: And the "start in" was set to the dir containing prepend-selection.ps1Lastly the "shortcut key" of the shortcut was set to CTRL+SHIFT+[ -- i couldn't use CTRL+[
... and it works. Open an app like notepad, put something on the clipboard, select some other text then ctrl+shift+[ with notepad still having the focus and... wait far too long but then eventually powershell.exe opens and i have the selected value prepended to my clipboard.
0 out of 10. Would not do again, AHK definitely beats powershell for this use case :-)
For #2 i know how to do that already - create a Shell.Application com object and then cycle through the window list and set width / height / top / left to suit.
For #3 i didn't try it but i wonder if there's a mechanism where i can insert a function to be called back into window's message processing loop. Like how i imagine AHK does it. This is just a thought, i'd just use AHK before i actually tried this.
For #4 this suffers the same issue as #1 with the "define a keypress" limitation but otherwise it's just an exec + focus window + send keys (likely with some hacky sleeps in between).