Live data from Hacker News

In Praise of AutoHotKey

hillelwayne.com

41–50 of 220 posts

Re: In Praise of AutoHotKey

#41
Did nobody else get a TLS (HTTPS) certificate warning for the site? For me it shows it expired 2020-04-26T14:00:00+0200 (I guess that would be pretty crappy for a MITM, unless that's exactly the point since an unknown CA would be more suspicious than someone "forgetting to renew their cert").

Re: In Praise of AutoHotKey

#42
post #41

Did nobody else get a TLS (HTTPS) certificate warning for the site? For me it shows it expired 2020-04-26T14:00:00+0200 (I guess that would be pretty crappy for a MITM, unless that's exactly the point since an unknown CA would be more suspicious than someone "forgetting to renew their cert").

Nope. The cert I get expires May 20, 2021

Re: In Praise of AutoHotKey

#43
I use AHK so I can have emacs-like text navigation in all apps and not just VS/VS Code. It is extremely liberating to be able to nav/select/delete all from the home row regardless of if I'm in VS, Word, Chrome, FF, etc etc.

Re: In Praise of AutoHotKey

#44
Specific ways to reproduce these AutoHotkey scripts on macOS (a repost of my comment on Lobsters):

## 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 ml s]%a()"*Pl

## Fast Window Switching

I 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.

Re: In Praise of AutoHotKey

#45
Oh god, I remember EMC made us use this to manage their god-awful support system.

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.

Re: In Praise of AutoHotKey

#47
I once automated myself out of a job, in my first banking internship, with AutoHotkey. I would fire up a script and then head out to lunch and be done by the time i got back, so then I went home.

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.

Re: In Praise of AutoHotKey

#48
AHK solved a quirky issue my work had me develop.

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.

Re: In Praise of AutoHotKey

#49

AutoIt ( I know this is about AHK but hear me out) was my first actual coding language. this was way back in 2008 when I was a manual tester and I decided to work on an automation framework around testing our .net based app. the documentation was amazing. the language are incredibly simple. and the windows integration was insane. In a way, if I hadn't worked on the automation framework using autoit, i probably wouldn…

I believe AHK was an early fork of AutoIt. AutoIt was my first language as well. A fun language to write code in. No static typing, easy to use. A little code can do a whole lot. I miss the forums, I wonder what ever happened to everybody there, Gary Valik Validator Larz SmokeN -- some names that come to mind. To think of all the devs that used this language as a stepping stone in their careers. Incredible. Hats off to Jon & Team!

Re: In Praise of AutoHotKey

#50
post #46

I remember back in 2005-2007, using AHK to make data entry way more efficient, at a few different companies. It's also great for macros in video games.

Pretty sure AHK/AutoIt made its way into many legitimate products despite its binaries being false-positively flagged by anti-viruses
Post reply on HN