In Praise of AutoHotKey
hillelwayne.com
hillelwayne.com
1. Use shift when pasting something to simulate typing in the text instead, getting around websites that block pasting.
2. Use ";" as a hyper key. By holding it down and pressing another key, I can switch between specific programs without cycling. I can also use hjkl as arrow keys.
3. Automatically switch audio input and output devices according to my specified priority order. Because macOS would frequently get it wrong, including treating my monitor as a speaker for some reason (it doesn't have built-in speakers).
4. Make control act as escape when tapped. I use this in conjunction with remapping caps lock to control in macOS system preferences. I previously used Karabiner Elements for making caps lock work as escape when tapped and control when held, but I was able to uninstall Karabiner because Hammerspoon was sufficient.
5. Disable the insert key because I've never wanted its functionality, but I would sometimes hit it accidentally.
[1]: https://github.com/dguo/dotfiles/blob/master/programs/hammer...
For paste blockers I've been using an Alfred workflow that types keys using AppleScript. It doesn't work with characters that require special input like ü, which is annoying, but it's sufficient for passwords. The benefit here is I'm not using up a global hotkey for such an infrequent use-case (especially not one actually used by other apps, such as Terminal.app).
Does Hammerspoon work just as well? Karabiner is so incredibly solid.
I'm hoping Karabiner Elements figures out some solution going forward. It still works on Catalina but the expectation is the "legacy kext" will no longer function on 10.16.
At my new job I'm afraid to download AHK at all :(
I am using it and am curious what are the downsides
One specific reason I want to go with Hammerspoon in the long run for key remapping is that I plan to do more complicated things, like setting up key layers. And even if that's possible with Karabiner, I'd rather maintain the complexity with Lua code rather than Karabiner's JSON configuration, which is complicated enough that someone created a separate tool[1] just to generate the configuration.
I should note that one of the maintainers of Hammerspoon specifically recommended[2] using Karabiner instead of Hammerspoon for key remapping because Karabiner was built to do that. Hammerspoon has a much higher level view of key events, from what I understand. I don't plan to do any remapping with modifier keys though. I plan to only use the letter keys for everything. Something like: press and hold ;, then press and hold v, and then tap a. And that will re-arrange my current windows into my preferred arrangement. Stuff like that. Based on my initial experience, I should be able to do everything with just Hammerspoon.
[1]: https://github.com/yqrashawn/GokuRakuJoudo
[2]: https://github.com/Hammerspoon/hammerspoon/issues/1025#issue...
This is quite common on HDMI monitors. Since the HDMI connection transmits both audio and video, the monitor just accepts both audio and video input. They would then have a 3.5-mm jack to allow you plug in an actual speaker or headphone to receive the audio output.
I use combination of BTT, Karabiner Elements, yabai and skhd to do remappings but this comment has intrigued me to give hammerspoon a shot!
Talking about automation, I use BetterTouchTool[1] to give me a few useful touch bar icons:
- Speaker and headphone buttons (using switchaudio-osx[2])
- Start meeting that starts a Zoom call and adds the link to my clipboard
- Write email that gives me a new blank email (and makes it visible)
This one really drives me mad. Is there really any legit reason to this?
By the way my hack is I paste it in the address bar, then just drag-drop into the field. Works 50% of the time or more (fails when a lot of these stupid websites don't use placeholder attribute but rather use some sort of Javascript for the placeholder text)
> This one really drives me mad. Is there really any legit reason to this?
No. Which is why I set the about:config option "dom.event.clipboardevents.enabled" in Firefox to false. That turns off the ability of websites to block pasting in Firefox.
Truly, there are very few legitimate reasons for a site to even know you've copied or pasted something. Makes me think this setting should be a whitelist.
Yes, preventing you to steal their content.
Of course this only works against the technical layman, who does not even think about googeling for a solution to this.
And I actually use caps lock as a "fn" key for hjkl/arrows. Who needs caps lock, really?
I've actually gone kind of crazy with this idea and made my left ctrl, shift and alt behave as fn+ctrl, fn+shift and fn+alt, so that e.g. left ctrl+h actually does ctrl+left. Then I made fn+[ = pgup, fn+] = pgdn, fn+; = home, fn+' = end and fn+\ = delete, with the same augmented fn+LHS modifiers.
Took me about a week for the muscle memory to catch up and allow me to correctly hit ctrl+L with the right hand when I want to go to the address bar, but now I'm ridiculously fast moving around in Excel without having to touch the arrow keys.
Only downside is I have a relatively problematic left wrist and this set up added to the already LHS stress to the already very imbalanced qwerty layout, so it forced me off mechanical keyboards to a low profile logitech right around the time COVID-19 hit.
If only Excel had vim bindings!!
Recent attempts to lock down the system point to how it’s “not the default” to customize your Mac outside the App Store. And I find the share sheet is still more useful on iOS than on macOS (for now?) just as Finder is more useful on macOS than Files app is on iOS.
That said, Windows Terminal and WSL highlight that Microsoft isn’t slowing down here and Apple might actually need to play catch-up at some point and evaluate new approaches to developer and power user pain points. (AppleCare-supported upgradable storage is on my wish list but that’s not technically the software’s fault... just a policy Apple used to have and then later removed from their website as they moved to proprietary SSD controllers)
Caps Lock is quite useful, because it's the perfect location for remapping the Ctrl- and ESC-Keys. Which is no surprise, as they originally where located there.
Under linux there is a nice tool for overloading keys, so they behave one way when pressed short, and another way when holded longer. With programmable keyboards you even have it OS-independant.
Name please (TIA)
I use https://github.com/alols/xcape for some while now. It's old, reliable and straight forward, just does it's job. Only downside is that it seems to be limted to X11. Not sure how well it will play with wayland.
There are now also some alternative tools, with more ability, which allow overloading just on the side. I have them on my list for a while now, but not done much yet with them.
- https://github.com/david-janssen/kmonad
- https://github.com/mooz/xkeysnail
- https://github.com/snyball/Hawck
Oh, and for rermapping capslock there are also options with X11. I use
setxkbmap -option ctrl:nocaps
to map ctrl to capslock, then overload it with xcape -e "Control_L=Escape;"
to add ESC ontop.[1] https://github.com/rcmdnk/vim_ahk#applications [2] https://github.com/yamsu/vibreoffice
Really, there are some really smart people at apple. You know some of them have customized their environment. You know apple has internal tools.
Why don't they get it and support customization of their os?
They're also not very supportive of "outside" tools. Say you want to use python on macos. Apple has only the most passing support for it. Same with bash or anything else that could put up a dialog box or whatever without having to compile/use xcode/other barrier to entry.
applescript doesn't count.
I know you can add software like macports or homebrew, but I mean first class support from apple.
Did you overload the ;-key, meaning it sends ; when pressed fast, and acts as modifier when hold and pressed with other keys? Is'nt that kidna painful to use and inflicts false input occasionaly?
I too have some personal modifier-keys. I remaped Pause-key to the Right alt-key, and use for persional settings in apps. And I remapped the left Alt-key to F22, and use it for window managing and staring/raising apps.
Benefit with this is that both keys are exclusively used by me and the pause-key is also available even when my setting is not available.
I find it very easy to use since my pinky finger sits on the ; key by default.
Wished there would be a better way to actually map hyper key that only is activated if pressed down. Well, I went back to BTT and setup fn + and this works too.
I showed it to my immediate manager who I liked; they had a huge backlog and issues with the health and safety executive. She was interested and I thought I might get a slightly better low paid job maintaining my script, but alas the overworked, underskilled, and somewhat frightened IT person couldn't stomach the risk of getting in trouble for using it. So a hundred or so people went back to doing things 6 times as slowly and much more error prone-edly. It's stayed with me as some kind of lesson about inefficient use of human capital.
It was the first time I can remember really solving a problem I had with software. Thanks ahk. You beautiful ugly thing.
> but alas the overworked, underskilled, and somewhat frightened IT person couldn't stomach the risk
this seems like a reasonable call to me.
He could have written his own program and just used it, and IT would never have gotten involved. Because it was using a 3rd party tool, IT got lazy.
My company, BTW, not only explicitly allows AHK, they actually encourage it. I mean, if you're going to give people compilers to write arbitrary code, this is not worse.
Imho, this IT guy did his job, more or less. What was the testing plan for this AHK script? What edge cases were considered? Unit tests, integ tests.... was there a preprod environment for it? A trial run? Can you safely roll back if / when bad data shows up? What's the retry strategy for network or up/downstream fault tolerance? Is there alarm or monitor coverage for bad scenarios?
I'm not saying a bunch of people typing are error prone, if that's your take on my post. I just think that there's a VERY different set of risks (and therefore mitigations) between a distributed manual process and a large scale automated one.
The IT guy might have on some level recognized this and judged the possible loss to be way more than the "guaranteed loss" of the not-broken current process.
If I were an IT guy with low level skills, I'd be proud of myself for making that hard call.
If a new tool is needed, a steering committee of some kind should be used, and IT will be one part of that.
Work would come to a crawl if IT had to validate every single tool used in our company. The notion that this is within IT's scope is flawed. It's the equivalent of asking a government agency to vet every single product that is produced by any company for consumer safety in the whole of the United States, and then rejecting most of them because of the lack of resources to thoroughly vet them.
If so, then they're completely right to stop some novice programmer from bringing their scripts to bear. There's no reason to take that risk if they have the funding for the current human solution. Bring it up to the superiors and pitch it, talk to some devs. I've seen groups lose hundreds of millions of dollars when one of these excel vbscript python enthusiast AHK things go off the rails. It's a mess, and - again - risk aversion is the most reasonable stance from a business standpoint. He's not a hacker founder, he's a business IT manager.
Edit to say, it sounds like you work at a company with <500 engineers, maybe even <500 employees total. That's fine! It's good even, but it's not an experience that's easily exported to the realm of Actual Business, at least not exactly. As a consultant, I've had billion dollar companies that need the fast fix (python script with a csv datastore to keep some account info or whatever) and I've worked for companies where this sort of approach would get you insta-canned. They're both right enough, but assuming one size fits all is absolutely crazy. It sounds like the mega oil corp above was the latter, at least to me.
As I said in my comments above, it's a question of who owns the data. In general, other than things like financial information and HR records, IT does not own the data in our company. They provide lots of services (version control, Jira boards, etc). They often are responsible for backing them up at a specified interval (daily, etc). And they are responsible for configuring them to be secure (which may involve shutting off APIs). But they don't own whether someone can write a script to automate clicking on fields, etc.
They don't own the data and outside of the agreed backup are not responsible for it. They absolutely would not get in trouble if someone automated something that destroyed that data. The policy is "We provide the service, but you are responsible for what goes into it and how." They do not need to see that we've vetted people's scripts for bugs, etc. They expect us to be responsible. If the data is lost, we will be in trouble, not them.
If IT was responsible for every database, Jira board, etc in the company beyond their regular backup, little work would be done. It's a huge company, and we cannot have one org be a bottleneck.
At times they do need to put some restrictions, but even in those cases, the department is free to get their own hardware and run their own database/JIRA board/whatever. There are a few security requirements to hook it up to the network, but IT will not get in our way if we set up our own Jira board/DB. They'll just tell us that we are responsible for backing things up nor will they provide support if we break things.
This is why my company has lots of pseudo-IT teams across departments. The company wide IT is responsible for the big things. The smaller pseudo-IT teams exist to be more flexible and not be constrained. They don't exist in defiance of IT - IT actually endorses it.
> I've seen groups lose hundreds of millions of dollars when one of these excel vbscript python enthusiast AHK things go off the rails.
But why is IT responsible for it? Perhaps in your company this is in their purview, but not in ours. And I'd argue that it shouldn't be. IT cannot go into every org and police what VBA scripts people use, and if they did they'd likely do more harm than good. While you may have seen losses of hundreds of millions of dollars, I'm pretty sure the gains from Excel VBA scripts is much, much more.
> Edit to say, it sounds like you work at a company with <500 engineers, maybe even <500 employees total.
Nope. Well over 50K employees, with over 60% of them being engineers. Likely the top company in the field we're in.
No one has answered my question that I brought up several times: If I can write my own program to do it, should they ban compilers as well? I'm sorry but whatever damage a VB script can do can also be done by C#. Should we ban Visual Studio?
I don't understand what that means. With noted exceptions, nobody owns specific data in any of the many companies where I've worked or consulted. You own data stores, get restricted access to other data stores... that's services, even if it's SOA/P. Standard for many many years.
> If IT was responsible for every database, Jira board, etc in the company beyond their regular backup, little work would be done. It's a huge company, and we cannot have one org be a bottleneck.
Not sure what this has to do with the situation at hand, where a user who was a part of a human data entry team dealing with metrics around oil rigs and live oil pipeline data decided to automate their data entry dayjob. No data stores or backups were touched beyond their contribution.
> No one has answered my question that I brought up several times: If I can write my own program to do it, should they ban compilers as well? I'm sorry but whatever damage a VB script can do can also be done by C#. Should we ban Visual Studio?
I don't understand your insistence that a language is meaningful. Why would the IT guy sign off on a haskell program, or a java program, or a python or awk or bash pipeline? He doesn't have the expertise to verify that it does what your job is to do. He doesn't know the guy's job, doesn't see testing, can't verify if it's right or not. With no verification of correctness, he's completely right to block it, no? I almost feel like I'm missing something here.
Sure, my employer allows me to run whatever I want on my laptop. They don't let me pump piles of data into prod environments from that laptop even if it's done in AHK, F#, ... whatever. Why would they? That's a crazy requirement to have.
If you have over 50k employees and each person is allowed to script prod data, let me know the name and some prod endpoints for your company. I'll give you a hundred bucks on the spot :)
You keep bringing up the oil fields, oil pipeline, etc. The original commented did not indicate that this is the purpose, and nor did he indicate the importance of said data, or the cost of the loss. I think I have an idea to what he is referring to, and the data is not that critically important. If it has some importance, there will be a paper trail. As another commenter said, they either have a process to audit the validity of data entry or they don't. Whether it was hand entered or automated is irrelevant.
Throughout this thread you've been arguing from extremes, invoking cases where such a thing could be disastrous, etc and using that as a general purpose argument. No one is saying there aren't occasions where IT should not interfere - I've acknowledged that there are cases where they should. There's nothing to indicate that the original commenters use case is one of those.
And this is what people in the thread are caring about: Someone who has no idea about the problem interfering with a perfectly fine methodology.
I could go on and address your other points in this and other comments, but I don't want to discuss this with someone who doesn't seem to understand the problem domain at all.
There's not been a response to my question of how you reconcile things after this script messes up for the first time; how does that happen? What's the DR plan? if you have real business and real clients working on this data, tell me what the plan is; it shouldn't be that hard.
Once again, if I wrote my own Python script they would not be involved, and my Python script is as error prone as using AHK.
Think of AHK as similar to a compiler + linker. By rejecting AHK because someone can write a program that could screw things up, you might as well just prevent people from writing scripts and compiling programs.
> I'm not saying a bunch of people typing are error prone, if that's your take on my post. I just think that there's a VERY different set of risks (and therefore mitigations) between a distributed manual process and a large scale automated one.
You've essentially argued that IT should oppose any automation that is not thoroughly tested. And how will they determine how well it is tested? Do they have those skills?
Where I work, IT is more concerned about security (viruses, theft, etc), licensing, and things that can break the machine. They don't prevent people from using APIs to mass edit databases as long as you do it to data you own or have permission from the owner. They don't own the data, so you're free to screw it up if you're careless. Ensuring my program is bug free and well tested is the job of my team/org/data owners, not IT.
You're merely pointing out that this IT person has been given more power than his skills warrant.
> You've essentially argued that IT should oppose any automation that is not thoroughly tested. And how will they determine how well it is tested? Do they have those skills?
In large scale, business critical applications? Yes. All everything should be thoroughly tested and/or canaried, with several levels of validation before production releases.
> You're merely pointing out that this IT person has been given more power than his skills warrant.
I think I'm pointing out that his job is to be a safeguard against rogue wanna-be programmers whose ability to destroy things far outstrips their ability to test for things (or even think about edge cases). If that's true, they've done a fantastic job.
A lot of programmers, or programming enthusiasts, thumb their nose at IT staff who naturally push back on stuff like this. In their mind, to play devil's advocate, they're seeing IT as unnecessarily burdensome, and getting in the way of automation.
The IT staff are probably naturally welcoming to the general idea of automation. However, to elevate something up from an off the cuff script that's described as "depraved" to the level of an actual business tool that can be relied upon, is a HUGE time and money sink. Validation is a very complex problem as you have described. This is the difference between consumer and enterprise hardware. If business management isn't setting this as a priority for IT, and if IT is already overwhelmed with the "known" quantities of work, then it just isn't practical to officially adopt.
I see it like this: It takes 1 "effort point" for a data entry staffer to manually enter the information tediously. It takes 10 effort points for the same staffer to write the AHK script to automate it. (Good for the staffer, assuming there's no flaws, and their reward is a longer lunch break.) To truly validate an automation as a business tool would take something on the scale of 150 to 200 effort points and involve lots of conversation - assuming there even is a framework for new tool validation established that can be used. IT knew this and made the right call. If company management wants to adopt a new tool without research and validation, that can be reckless.
Which raises the question, why does such a person even have the authority to make calls on what software can or can not be used within the company? You shouldn't have the right to make these kind of decisions without basic understanding of how software works (beyond "I click stuff and things happen, magic!").
> What was the testing plan for this AHK script? What edge cases were considered? Unit tests, integ tests.... was there a preprod environment for it? A trial run? Can you safely roll back if / when bad data shows up? What's the retry strategy for network or up/downstream fault tolerance? Is there alarm or monitor coverage for bad scenarios?
Without understanding of how software is built, those are questions the IT guy can't possibly ask thoughtfully. They become a mere checkbox ticking exercise. And most of them don't apply anyway.
> If I were an IT guy with low level skills, I'd be proud of myself for making that hard call.
It's not a hard call. It's the easy call. The ass-covering, responsibility-mitigating, work-minimizing, consequence-free default deny call.
> Unit tests, integ tests.... was there a preprod environment for it? A trial run? Can you safely roll back if / when bad data shows up?
Nothing of the sort :)
But... Let the adequate be the enemy of the less awful?
To give some context this was a utility company. The gas pipes were consumer and commercial supply lines. You need to know where they are buried so people don't blow themselves up digging them up. It was safety critical.
>> It was really quite depraved but it worked
The baseline context for this, though, is a very error prone process. It was common for me to register a pipe in the technical specification (size depth etc) system and map that (by rekeying the handwritten ID) and accidentally pick a different location in the system for indicating connection of service to main pipes. You could have a service pipe (to someone's house) registered to a main in a completely different area. My script eliminated these types of errors.
The other thing to note is it didn't change the underlying process. You could, and I did, check the underlying form fills (something I wouldn't bother doing when it took 6 times as long).
I'm not trying to denigrate the individual here, he might have been doing his best given his knowledge and level of autonomy (he might also have been chickenshit) but as an organisation they let some value fall on the floor from an employee because they had no mechanism to capture and integrate it.
I can't imagine being at the mercy of computer tech in areas of being the master of it.
I did something similar around the same time parsing out some archaic TSV format. I forget the details of it all but we were copy-pasting from Notepad to Excel which I think involved changing some Notepad word wrap preference with every file? I think the objective was to get a CSV file and then FTP it somewhere?
Anyway, I wrote a powershell script I think it was, maybe I managed to install python? Whatever it was I basically replaced myself with a shell script and spent my spare time posting on somethingawful. Which actually did lead to a better job interview. Overall a good use of my time.
I hadn't thought about this for years. Thanks for reminding me, I think.
These days I use it for fewer things, but still really useful. One of those is making chat applications that don't offer ctrl+enter to send a message - Like Google Hangouts (basically flopping the functionality):
#IfWinActive Google Hangouts ahk_class Chrome_WidgetWin_1
^enter::
Send {Enter}
Return
enter::
Send +{Enter}
Return
Another extremely useful is this one, which will type what's on the clipboard rather than pasting it: >^v::
SendRaw %clipboard%
Return
And when I hit shift also, it does it slow (for input lag situations): >^+v::
SetKeyDelay 500
SendRaw %clipboard%
Return
Extremely useful for two main reasons. 1 being input boxes on websites that prevent pasting and 2. certain remote sessions that prevent pasting (like Kesaya or any kind of Console remote application).I don’t understand this insanity around bank account numbers... they should be treated as public info, they’re on every single check, anyone you’ve given a check to has your account number as does your employer...
Funnily enough (in a sad way), 40% of the JS load on that page appears to be anti-pasting logic & supporting libraries. It appears to be developed in-house, since the scripts aren't obfuscated and a quick search of duckduckgo didn't match any open-source libraries that I could find. If they weren't reliably the cheapest carrier with the fewest issues I would raise a stink, but it's not worth it. That, and I just bypassed this 'feature' with a very similar AHK script, and their website has a very nice UI besides that issue.
Thankfully I've never had to deal with #2
many years later I am now a software engineer, I just wanted to manage my catapult on Age of empire 2 ....
So AHK is very powerfull, easy langage and awesome !
--
I first used it to automate grinding gold and items in a simple flash-based RPG for me and my younger siblings around ~2005. At first it just clicked certain locations that buttons would be on a fixed schedule to advance a quest to the end and repeat. But then, being a flash game after all, sometimes it would take a second to load the next screen which throws off the timings and breaks the sequence. So I changed it to wait for pixels to change color as an indication that something finished loading and to start the next sequence of clicks. But that didn't end up being very reliable because the colors & locations weren't always exactly the same, so I updated it to take a screenshot and use it to find the average color of an area of the game where a button would be which ended up being a much more reliable timing indicator. But then it was very slow/used a lot of CPU (and I needed all that CPU to go to running the flash game in a 2005 browser on a 2002 dell), and using a scripting language to sum up 100k pixels every frame just wasn't fast enough. So I wrote a single C function to do the color averaging on a byte buffer, copied the raw compiled machine code (as hex) into AutoHotkey and directly called it with DllCall to get the summed result: ah, much faster. But there was still an unreliable aspect where the position of the game in the browser window and the location of the browser window was fiddly to configure, and my siblings had a hard time getting it set up. It turns out IE used standard windows controls in the browser which (if you look in the right place) exposed the location of the flash bounding box, and with some calculations relative to the browser window I made all the click locations relative to the flash window, which solved that problem. It think it also supported browser scaling because we liked to play it at higher than 100% zoom.
I ended up being more interested in the programming than the game, and my first published project was an array library to make working with associative arrays (where each element is a separate variable myarray1, myarray2, myarray3 etc) easier with insert/delete/append etc operations, before AutoHotkey added true arrays and objects.
Then I went to university for chemistry for 2 years before getting my wits about me and realizing that I would probably be more interested in CS.
I’ve been a swe for years, but this is how I felt about Pokémon go before they started blocking the apis people had developed. My only goal was to catch all 151 Pokémon. Because of where I live, I had a very hard time finding pokestops so I looked into and found the apis.
I was able to grind out lvls and catch Pokémon, spin stops, etc. I won’t go into all the things I did, but it sure was fun. I suppose I was harming the game because I wasn’t spending real money on in-game items, but besides that I don’t think I was harming any of the other players.
APIs got shut down, haven’t touched it since.
Holy potatoes, you can do that?! Or, I suppose, you could do that, because I half-expect you can't anymore with all the various security features that were added to Windows over the last two decades. But cool stuff nonetheless.
It reminds me of my own foray into the space of running assembly output; back in my teenage years, I compiled a small bit of assembly into an object file, read it into a C++ program, casted the string into a function pointer and executed. Surprisingly, it worked. I got the idea from StarCraft modding scene; in those days, if you wanted to add a new button for your unit that did something, you had to write the action in assembly, compile it with MASM, and then let StarGraft tool patch the game executable with it (I don't remember if it did it at runtime or modified the actual executable).
[1]: https://gist.github.com/infogulch/d88b956ddd86bd00b351649511...
Right Alt becomes Ctrl Tab: Ralt::^Tab
Common typos: ::teh::the ::alreadsy::already
::nopity::Call to undefined function pity()
::awk1::awk '{{} print $1 {}}'
::du-m::du -m --max-depth=1 | sort -n
But it goes waaay behond this. I once used AHK to assist my grandfather, who in his old age had caused him to lose dexterity. He was clicking both right and left mouse buttons at the same time. I used AHK to disable the might mouse button and then mapped right click to Number Pad +. Worked beautifully.
I actually wrote a Big Long Article about it once: https://www.tidbitsfortechs.com/2013/10/using-autohotkey-to-...
:*:netowrk::
Send, {Home}+{End}{Delete}
return
What it does: I have a really bad habit of misspelling "network" that way. I think my right hand is just so eager to get that 'o' keyed in that it doesn't wait for my left hand to hit the 'w' first. So I'm always screwing that word up when typing quickly.So now, when I make that mistake, I'm punished by having the entire line of text deleted. '{Home}' moves the cursor to the start of the line, '+{End}' is the [Shift]+[End] key to highlight the whole thing, then {Delete} metes out the justice I deserve.
There, fixed :).
It’ll be like my very own ransomware!
https://en.wikipedia.org/wiki/Compose_key
Edit: by the way, these compose sequences also work under Wayland. The only hiccup I found with wayland was that include directives didn't work so I had to put everything in a single file.
I wish there were a Unicode lookup utility app that would display a character's compose sequences if any, but none seem to be under development / accepting feature requests or patches.
I love my Compose key. When I looked into purchasing a Surface Book (and switching to Windows) some four years ago based purely on its specs, the two critical factors were WSL and WinCompose—without either one of those two, I couldn’t have, wouldn’t have switched.
(I also use an AutoHotkey script for a few other things like remapping Win+F to maximise/restore, and disabling the horrifically slow Win+Tab which was too easily triggered by accident.)
AutoHotkey started out as a fork of AutoIt by Chris Mallett, who stopped development around 2010 or so. Then Steve Gray (Lexikos) continued development under a fork called AHK_L, which later became AHK v1.1, and he's been the sole maintainer ever since. The GitHub repository is still fairly active, and I believe the v2 alpha is fairly stable, so I'm curious as to what changes still need to be made before it's done.
It's equally as {sometimes awesome, sometimes infuriatingly quirky} as its Windows inspiration :D , but I guess it's the nature of such a tool :) .
Won't work (yet?) on Wayland, though, https://github.com/autokey/autokey/issues/87 .
Instead, I derived my own little shell script snippy.sh [1] that expands a fuzzy selected string by letting xdotool type it out.
Passersby, warning, both are Xorg-only. For wayland, see https://github.com/ReimuNotMoe/ydotool but the naming is confusing, as it doesn't work exactly at the same level: ydotool is about keystrokes, not window management.
PS - I use Alfred and Keyboard Maestro to get functionality similar to AHK on a Mac.
We recommend that you just park it in a corner of your screen and turn on an auto-reload tool.
there is the COM object that detect the same sort of things but in web browsers, but it only works in IE only. for firefox or chrome you would need to use selenium.
maybe these things can detect certain things being clicked as well? i dont know
https://wiki.nikitavoloboev.xyz/macos/macos-apps/keyboard-ma...
PS: great site!
I first found out about AHK via Tom Scott's similar ode here:
https://www.youtube.com/watch?v=lIFE7h3m40U
He describes it as “a bodge that helps you make other bodges”, which is beautifully put.
[For those outside the UK, a “bodge” is a clumsy hack or repair.]
The video also reminded me to let some of the young guns in my team into the AHK secret
But his example, creating an emoji keyboard, would be far easier with Linux. And Linux is cheaper (in terms of money, not necessarily time). Someone in the YouTube comments actually posted how to do it in Linux, which is basically:
xinput list
xkbcomp $DISPLAY mapping.xkb
vim mapping.xkb
xkbcomp -i <id from xinput> mapping.xkb $DISPLAYNow, AHK is set up to just reads my design spreadsheets and define everything in a few minutes. I hate the language syntax, but man is it useful! God bless AHK!
wish I got the hint that i might have what it takes to be a developer right then. instead I waited ~6 years climbing the rungs in finance.
If you run Windows on a ThinkPad or similar machine, and you ever wished you could have precise pixel-by-pixel mouse movement from the keyboard home row, try it out.
I think it's also a good example of some fairly well-written AutoHotkey code. (Please ignore the messed-up indentation in the SetKeyMap function... Time to add a .editorconfig file!)
I originally wrote JKLmouse as a native Windows app in C using keyboard hooks. But when I saw that I could do the same thing in AutoHotkey it was a big improvement.
All the buttons, TVs, lighting effects... all run from windows PCs with AutoIt!
(there was a flash photo gallery, because 2007, but here are some of the images)
https://www.etc.cmu.edu/projects/lbe/S07/clients/ETC/gallery... https://www.etc.cmu.edu/projects/lbe/S07/clients/ETC/gallery...
So, much love to the AHK/Autoit team.
We have an excel sheet that gets updated periodically throughout the day by various people. When the spreadsheet is saved it also publishes an MHT file to be displayed on a webbrowser that refreshes every 5 minutes. That browser runs on a little Intel stick plugged into a wall-mounted TV to show the spreadsheet to various parts of the office / production floor.
At night the screens get turned off and through something that happens the little computer thinks the resolution changed and takes the browser session out of its fullscreen view to a tiny square in the corner.
No matter how many setting changes I made it still did it. AHK to the rescue. On a periodic timer take ownership of the browser window and compare its resolution to the desktop resolution. If it has changed send F11, pause, F11 to refresh the fullscreen command and boom, fixed.
That's the first use I had for AHK, I've expanded a lot on that since.
I dual-boot and leave my home PC on for weeks at a time; I just power the screens off when I stop working. My Linux system doesn't even notice; when I come back, everything is at it was. Windows however, the second it notices I powered off one screen, moves all the Windows to the other one. So the first thing I have to do when I come back is to rearrange the windows back to where they were.
I don't know the justification for this behavior of Windows.
https://superuser.com/questions/453446/how-can-i-stop-window...
https://answers.microsoft.com/en-us/windows/forum/windows_10...
Particularly st99's answer on the second link.
I'm not an AHK expert. Very much a beginner. This was trivial.
otherwise there is AutoGUI that makes it really fast since you just have to drag and drop the elements you want
> the resulting script can be bundled into an .exe file
thats another thing that i dont see mentioned enough about autohotkey. being able to make scripts for other people and giving them just one file to run is so underrated!
I still remember my favorite scripts and miss them dearly:
- a smart "spell check" of sorts that could look at previous characters or words to contextually fix typos and expand abbreviations, powered by regex. For instance it would recognize common typos like `AUtohotkey` where your finger would linger on shift for too long. Or auto-add a closing parentheses, if the previous character wasn't a colon (in case you wanted to type `:(` etc.
- I was a huge fan of OSX and specifically wanted to have something like Quicksilver back then but could not afford a Mac. So I built Quicksilver with AutoHotKey and used that. It had a cache, contextual actions, periodic rescanning, would search not only files but also Preferences and fuzzy search with custom scoring. God I loved this thing.
Fun fact, the current logo was contributed by me waaaaay back in the day :)
I started playing Path of Exile a while ago and soon found PoE Trade Macro (https://github.com/PoE-TradeMacro/POE-TradeMacro) which allows you to mouse over items, hit a hotkey to send a web API request to a trade site, pops up an overlay with a pricing summary, lets you adjust certain parameters and search again, and so much more. All allowed by the game in case you're wondering, they encourage it.
There's a YT video in the link above showing just some of the features. And I'm pretty sure newer overlays are even more impressive (I haven't checked them out). AHK is far more developed and complex than I gave it credit for.
Its free, light weight, and has an excellent user manual.
For "Fast Window Switching":
Linux: Use jumpapp: https://github.com/mkropat/jumpapp
OS X: Use triggers in QuickSilver: https://qsapp.com/
This is one feature I could not do without in any OS now.
[0]: https://www.youtube.com/watch?v=3AtBE9BOvvk [1]: https://www.youtube.com/watch?v=lIFE7h3m40U
I often use Siri on my iPhone to write messages, etc. It’s pretty good but at times frustrating.
How does Dragon on Windows compare? I like the tablet form factor. Does Dragon work well on a Surface Go?
I bought a logitech trackball, which is great for my RSI, but unfortunately it has no scroll wheel/button, and man, life without scroll wheel and middle click is just impossible!
Luckily, it has 4 buttons apart from the ball, so someone wrote a script to make use of one of those buttons together with the ball to provide the scroll wheel / middle click experience, and posted it on the forums.
Really great that a tool like this exist for this kind of situations.
I remember using it to automate login for a variety of websites, and to automate resource collection for a game I played (Lord of Ultima, in case anyone remembers it).
It beats the hell out of copy-pasting from one app to the other and hoping you're doing it right. 8 hours of data entry you are bound to make mistakes.
AHK also helped me move into more technical work, so I have a real soft spot for it. However, I am lamenting the move to SaaS websites because not only are there about 3x as many clicks as a native app, but it's really hard to automate with AHK.
MButton::
If (A_TimeSincePriorHotkey < 150)
Return
Send {MButton}
ReturnIt was simply too far to reach 6,7,8,9!
Then I used it to make a hotkey to have a popout, always on top, no title bar, browser window. I use that for youtube videos or documentation. Always on top windows + a big monitor are really great for productivity, better than multi monitor imo.
but yes autohotkey is great!
Check out my script if you are interested: https://github.com/pokerregion/pokerstars-autoit
It was a pretty extensive formula support [2] enabling you to create dynamic snippets. In many ways it's kind of like Excel but for documents.
Caps+p Ctrl+Backspace Delete previous word Caps+f Backspace Caps+d Delete Caps+h/j/k/l Left/Down/Up/Right Arrow Caps+u/i Home/End Caps+m/, Page Down/Up Caps+e/r Ctrl+Left/Right (next/previous word) Caps+3 Insert current date, e. g. 14.05.20 Caps+Shift+3 ISO format 2020-05-14
I also swapped Return with ' so it's closer to my pinky. Not sure if that was worth it, though.
Caps+p Ctrl+Backspace (Delete previous word)
Caps+f Backspace
Caps+d Delete
Caps+h/j/k/l Left/Down/Up/Right arrow
Caps+u/i Home/End
Caps+m/, Page Down/Up
Caps+e/r Ctrl+Left/Right (next/previous word)
Caps+3 Insert current date, e. g. 14.05.20
Caps+Shift+3 ISO format 2020-05-14 printscreen::
thumbMod := true
return
printscreen up::
thumbMod := false
return
#if thumbMod
l:: send {left} ; move caret
`;:: send {down}
p:: send {up}
':: send {right}
+l:: send +{left} ; select text
+`;:: send +{down}
+p:: send +{up}
+':: send +{right}
,:: send {backspace}
.:: send {delete}
#ifI have enjoyed reading the comments here, I have picked up some good tips; obvious ones I should have actually thought of.
I am glad I am not they only person who started programming using this language. I have to say that in my limited experience the documentation for Autohotkey is second to none despite that the syntax could use improvement.
It allows me to automate sentences or commands I frequently type. It also helps improve ergonomy of given websites (e.g. "page down" key rather than clicking on "next page").
It avoids the need to download dozens of software to do "this" or "that", piling up in the windows tray. If I need something, I write my AHK snippet.
And of course I have AHK shortcuts to Excel macros. And I have Excel macros that run AHK code :-)
Extremely simple! https://gist.github.com/cdaven/360f0509f823d309e1b9de67bd826...
So I wrote a Windows keyboard hook in C which turns out to be easy enough to do. I just hard-coded the key mappings in a switch statement. Been using it for about 10 years and find it hard to work without it.
Of course on the Mac, I heavily use Keyboard Maestro and LaunchBar so I am really implementing my own keyboard centric UI
Do you use one? Which? I used one, very convenient, in eighties(!) and haven't seen something comparable since.
The functionality I had then that I liked was: any key could be programmed to really anything else (except the special "macro" key) -- another key or another sequence of the keys, and I regularly did some action once, recording it with just one "start recording" and one "stop and assign to.." action and after that just "playing" it when needed. It was a huge time / nerves saver at these times, especially because it was fully independent of the programs and even of which OS I've used (I've had to switch between two even then).
Huge time saver!
Have been using this for years and years and finally published to GitHub a couple of years ago.
One of the worst experiences of my life in IT. Not the fault of AutoHotKey but they used it to paper over the cracks in their massively flawed and sucky support system. The only thing I’ve used that is worse than the SAP GUI.
You can mess with league of legends folks a lot with it actually. You can use it to spam 5 pings around someone instantly. You can spam emotes with it. You can write messages quickly in chat.
A clunky as it is, it is a fantastic tool.
I found it tedious to write long macros manually, so I wrote my own tool https://github.com/rmpr/atbswp, for fine grain control AHK is very good, but for quick and dirty things I rely on atbswp.
but it only works with other programs that are running in wine so theres not a whole lot you can do with it at the same time. ive mostly been using it to process strings and that sort of thing.
ive been thinking i should try and make a list somewhere of what is working and what isnt. it would make it easier to test things every time there is a new version of wine released
i made a script for autokey that will run the selected file in wine when you press alt + r. if you download the portable version of autohotkey and add the path to it then you can use the same hotkey to run the a script
https://gist.github.com/davebrny/9850223119c4ee55485dfae1fcb...
## AutoHotkey equivalent
The closest equivalent to AutoHotkey in general is Keyboard Maestro (https://www.keyboardmaestro.com/, currently $36), a proprietary app. In Keyboard Maestro, you define macros using a drag-and-drop scripting language. You can also embed shell scripts or AppleScript. Each macro can have a number of triggers, most commonly Hot Key triggers.
## (Keyboard and) mouse shortcuts
Keyboard Maestro’s triggers can associate custom shortcuts with your macros. Most of my macros have Hot Key triggers, which capture to keyboard shortcuts. For example, Shift+Ctrl+S triggers a macro that puts my laptop screen to sleep.
However, to respond to a mouse input like Scroll Wheel Left, you would have to use a Device Key trigger. A Device Key trigger responds to a single device input, but sadly, it doesn’t block the input from being passed to the OS. In this example, whatever your cursor is over would scroll left in addition to the macro being activated.
To replicate the `Send, {NumpadAdd}` part of your script, you would add a Type a Keystroke block to your macro. One nice thing about KeyboardMaestro is it can record the keystroke, so you don’t have to remember names like “NumpadAdd”.
If you don’t want to buy Keyboard Maestro, macOS’s built-in Automator (https://support.apple.com/en-ca/guide/automator/welcome/mac, free) can be used in some cases. For examples, compare three of the solutions on https://apple.stackexchange.com/questions/137047/ for working around bad default ⌘C behavior in Books: my simple Keyboard Maestro solution, someone’s straightforward Automator solution, and my shorter, situation-specific Automator solution.
## Hotstrings for math
I used to use TextExpander ([TextExpander]: https://textexpander.com/, currently $40/year) for something like this. I had `ddate` mapped to the current date, and `solang` marked to a block of markup I used on Stack Overflow. TextExpander implements the direct equivalent to AutoHotkey hotstrings, and is probably the best way to implement short hotstrings like `;a`.
However, for my purposes, I realized that I could insert pieces of text more simply by using another program I was already using: LaunchBar (https://obdev.at/products/launchbar/, currently $30). While its most obvious feature is launching applications, one of its many other features is inserting text snippets. You define text snippets by putting text files in a certain folder. Your defined snippets are then added to your global list of searcheable items, alongside applications you can open and so on.
To insert a snippet such as the current date using LaunchBar, I open a LaunchBar window with Command-Space, type `date` to find the “Current Date (ISO format)” snippet, and press Return to insert it.
Also note that macOS makes typing special characters easier in general. All macOS keyboard layouts let you access an alternate layer of characters by holding Option. For example, Option-8 types ‘•’. If you would rather Option-A typed ‘∀’ instead of ‘å’, you could set that up by defining a custom math-focused keyboard layout with Ukelele (https://software.sil.org/ukelele/, free). I have used Ukelele to define my own keyboard layout “U.S. – Rory custom” that makes smart quotes and apostrophes (“”‘’) easier to type.
## Markdown links
You could do this with Keyboard Maestro. It has actions for reading from and writing to the clipboard, and for appending to, prepending to, and searching and replacing in text variables.
Just a few days ago I implemented a Vim editor mapping to do a similar thing: turn the selected text into a link with the clipboard used as the URL. Of course, it only works in Vim. Here’s the source:
" create Markdown link from selected text using URL in clipboard
" uses vim-surround, so can’t be vnoremap
vmap <Leader>ml s]%a()<Esc>"*Pl
## Fast Window SwitchingI used to have something set up for this. I used Karabiner (formerly KeyRemap4MacBook) to map my fn key to the combination of Shift-Control-Option-Command. Then, with Keyboard Maestro, I mapped ⇧⌃⌥⌘F to open the Finder and so on. That let me type fn+F to switch directly to the Finder.
Karabiner was forced to be rewritten as Karabiner-Elements (https://karabiner-elements.pqrs.org/, free and open source) because of changes in macOS, and it lost some features in the process. I haven’t checked if mapping of fn is one of them. I don’t use Karabiner-Elements because I rarely used my fn mappings and my current model of laptop doesn’t have real function keys to remap.
As for window groups to switch within, Keyboard Maestro doesn’t have a built-in concept like that. I think you could implement it, though – “if” statements can check the app of the current window.
## Remapping the calculator button
This would be a straightforward application of Keyboard Maestro.
## Scihubize
Same as above.
---
That covers everything in your article as much as macOS software is capable of. You may also be interested in…
## Features I use without equivalents in this article
Keyboard Maestro lets you define a Quick Macro – a sequence of keypresses and clicks. I can press Ctrl-F1 to start recording, execute a sequence, then press Ctrl-F1 to stop recording. After that, Option-F1 will run the sequence. I use this, for example, in my browser to scroll many adjacent newly-opened tabs down to the start of the content, by recording and replaying the sequence Ctrl-Tab, Down, Down, Down, etc.
Keyboard Maestro also supports image recognition for clicking on the screenshotted GUI element or waiting for something to appear on the screen. I’ve used this to make a macro that uses the System Preferences GUI to toggle a setting – it decides whether to move the selection up or down by recognizing the image of the currently-selected preference. I’ve also used it to abort a macro if I don’t see the expected window open after a certain step (which could happen if the GUI was in a certain state), to avoid executing further keypresses in the wrong window.
LaunchBar comes with a built-in clipboard history manager. I use this to copy, for example, both a title and URL in one window, knowing they will be saved. Then, after switching to another window, I use the clipboard history to paste both of them where they need to go.
Remarkable piece of software. Wish something like that was for *nix.