4 ms·
The AutoHotKey programming language is quirky and weird, even when compared to Powershell's quirkiness, but there are classes of things that AutoHotKey can do t
by yardshop 6y ago
The AutoHotKey programming language is quirky and weird, even when compared to Powershell's quirkiness, but there are classes of things that AutoHotKey can do that I don't know how you would do on Powershell:
prepend or append selected text to what's already on the clipboard with Ctrl+[ or Ctrl+]
find all windows with specific text in the title and resize them in a custom way (Window+])
insert custom strings or large blocks of text in other programs triggered by a keypress (its original reason for being)
eg: ]s inserts the current date and time: 2020-12-25 11:57:07
define a keypress to start Putty with a given profile, enter logon credentials, CD to a folder and start Midnight Commander
(these are my own keypress definitions)
I once wrote an AHK script to start VLC streaming a local radio station at a specific time, then start Audacity to record audio, then stop the recording and streaming at the end of the program and save the audio as WAV and MP3. This let me go for a bike ride in the late afternoon before dark, then come home and listen to my favorite radio show later in the evening. It's not necessary anymore, but back in 2008 this was an amazing thing to put together.
- CraigJPerry 6y agoThis 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: powershell.exe -executionpolicy bypass -noexit -file prepend-selection.ps1 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).
- majkinetor 6y agoThe 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.
- majkinetor 6y agoAHK language sux. Shame it is not Lua instead of it. But tool is awesome, and community is great.
- sixothree 6y agoI write code all day and I can't be bothered to learn AHK. I tried but it annoyed the heck out of me.