[HN Gopher] Hammerspoon - Lua-based powerful tool automation of ...
___________________________________________________________________
Hammerspoon - Lua-based powerful tool automation of macOS
Author : gurjeet
Score : 65 points
Date : 2021-12-12 20:52 UTC (2 hours ago)
(HTM) web link (www.hammerspoon.org)
(TXT) w3m dump (www.hammerspoon.org)
| endymi0n wrote:
| Really nice at first sight.
|
| I'm getting melancholic vibes of AutoHotKey reading the docs,
| which was arguably my first entry into professional programming.
| Knowing nothing about coding, I built a service desk automation
| back then -- with (network file-) shared hotkeys and a real GUI,
| all in one single file... good times.
|
| Anyway, ever since switching to MacOS more than a decade ago,
| I've always been searching for an AHK analog for those simple
| keystroke automations, text-based, with just enough of a glue
| language to hold it all together -- Automator never quite cut it
| for me, after wielding the full power of AHK, it always felt too
| limited, rigid and clicky-colory.
|
| Even though I don't have immediate use cases for it anymore, it
| makes me very happy that I know where to go back now!
| blondin wrote:
| do you mean simple text-based replacements and keyboard
| shortcuts? as opposed to full automation?
|
| you can set those in the keyboard settings in system
| preferences. i have used the text replacement tab a lot in the
| past. i used it to auto-insert smileys and text snippets on
| various platforms. i haven't used shortcuts much though. you
| always end up with complicated shortcuts so you don't conflict
| with your apps.
| blacksmith_tb wrote:
| I have been enjoying espanso[1], which at first glance is just
| a text-expanding keystoke saver, but can run shell scripts when
| it's doing its thing. So I can type :extip anywhere and it will
| curl ipinfo.io then pipe the json response through jq -r and
| leave my current external IP in whatever app I was typing in.
|
| 1: https://espanso.org/
| artdigital wrote:
| Have you tried AppleScript scripting? You can glue applications
| together and even use JavaScript if you're not a fan of
| AppleScript
| endymi0n wrote:
| Did some, but the syntax wasn't my cup of tea. The _really_
| great feature of AHK to me was having the triggers and the
| actions all in one place though, which is something I
| couldn't really replicate with AppleScript that only has the
| actions, with the triggers in Automator.
|
| So with that runtime you could easily just write whatever
| would happen if you press which key combo (or do cronjob-like
| things managed by the runtime) and then write what happens
| inline.
|
| Write it all to a single script, copy it to a coworker's
| computer, run it, several dozen key combos just work now.
|
| That's something I couldn't manage to pull off in AppleScript
| or Automator, but then again maybe I was just too dumb.
| 1123581321 wrote:
| Try Keyboard Maestro or BetterTouchTool. They remind me the
| most of AHK out of all the Apple options.
|
| I also really like Hammerspoon. The desktop automation
| scene on macOS is strong.
| christiangenco wrote:
| I love Hammerspoon. It's one of the first must-have-for-a-usable-
| laptop tools I set up when I get a new MacBook.
|
| Here are the top ways I'm using it right now:
|
| 1) Hide/show apps similar to how iTerm lets you bind a hotkey to
| hide/show a terminal. I've got ctrl+space set to Vimcal,
| alt+space set to midnight.app (a time tracker I'm building), and
| ctrl+alt+space set to Things.
|
| 2) Start/stop playing my work playlist of lofi hiphop. I got
| tired of the friction around opening Spotify, going into my work
| playlist, hitting play, waiting several moments for the playlist
| to load, etc, so I downloaded a bunch of mp3s from YouTube and
| put them in ~/Music/work/. Now my work music is a single keyboard
| shortcut (semicolon+m) and a few miliseconds away.
|
| 3) Set up screen recording. There are a few things that need to
| happen before I start a screen recording (opening CamHead.app,
| setting my screen resolution, and showing the dock at a certain
| height so I can later crop the video to 16:9) and I have it all
| bound to a single hotkey (semicolon+r). I've got another hotkey
| set up to unset it (semicolon+e).
|
| 4) You may have noticed I'm using keyboard shortcuts with
| semicolon as a modifier key. That's done with Hammerspoon too!
| I've got an extra layer of hotkeys available to me to set up
| whatever else I can think of in the future. The code I wrote to
| use semicolon like this sometimes breaks if I try to type too
| many _actual_ semicolons in a row but I usually rely on JS
| Beautify to add those for me.
| VWWHFSfQ wrote:
| Hammerspoon is fantastic. And Lua is a such a fun little language
| to program in. And with LuaJIT [0] you can run it on your nginx
| webserver [1] at basically the speed of C code. It's really a
| marvel of engineering.
|
| [0] https://luajit.org/
|
| [1] https://openresty.org/
| dorian-graph wrote:
| I use this!
|
| - Mute my computer when I put it to sleep or when I change wifi
| networks
|
| - Hyper key
|
| - Mail.app menubar indicator
|
| - Spotify menubar current song
|
| - Shortcut to move mouse cursor to another monitor
|
| - Window switcher that only lists apps in the current workspace
| pkukkapalli wrote:
| Just curious do people use these types of automations to help
| with coding/software engineering? If so, in what way?
| riston wrote:
| I really like HS especially filling the macOS missing features
| place like for windows management + either opening/focusing
| specific applications with shortcuts.
| pjm331 wrote:
| I like hammerspoon. I've been using it for years and never got
| beyond setting up window resizing with the visual grid - which I
| think is like one of the very first steps in the tutorial - but
| I'd recommend it just for that.
| [deleted]
| cmsj wrote:
| Since we've hit the front page of HN again, I've just released
| Hammerspoon 0.9.92, which contains a few fixes and some
| additions, but mostly refactored a significant amount of internal
| project structure to allow our build system to be replaced with
| something that isn't 5 years old and terrible.
|
| As a result, it's possible that something broke which we didn't
| find in our internal testing. Please file GitHub issues :)
|
| Happy Christmas y'all!
| nsonha wrote:
| Does anyone knows a cross platform tools that can map keyboard
| keys to mouse button? Preferably in a layer?
| Arubis wrote:
| I've especially enjoyed using Hammerspoon in combination with the
| prebaked config "Spacehammer"
| (https://github.com/agzam/spacehammer), which takes a lot of
| inspiration from Spacemacs (and, of course, enables a systemwide
| "edit this text field with emacs" workflow).
| wasyl wrote:
| I like Hammerspoon, but it's a bit of a pain to write the scripts
| with Lua - I don't use the language often and it usually takes a
| while to figure out syntax and necessary stdlib/Hammerspoon
| functions. Does someone have a hint on how to set up e.g. VSCode
| or IJ with Lua support and completion for Hammerspoon functions?
| faizshah wrote:
| Is there something like this for python?
| Syzygies wrote:
| I fell briefly in love with Hammerspoon, but stopped using it.
|
| My MacOS automation is now my QMK keyboard calling Alfred
| workflows; I use Yabai for window management.
|
| I admire Lua, but ran into some sharp edges learning to program
| in it. Still, one can get up to speed quickly if one knows other
| scripting languages.
|
| Hammerspoon window management was deathly slow. Yabai is close to
| instantaneous.
| cranekam wrote:
| Hammerspoon is great. I use it to manage windows (eg set vscode
| and a browser side-by-side when connected to an external display,
| full screen when not), add a hotkey to translate selected text
| with Deepl, to mute sound when the machine sleeps, and to launch
| a terminal with an fzf-based browser history searcher that beats
| Firefox's hands down.
|
| It's easy to use and has great docs. Lua is fun to write. HS is a
| really nice project.
___________________________________________________________________
(page generated 2021-12-12 23:00 UTC)