Presenting Hammerspoon-HX

I’m my ongoing effort of “Haxe all the things”, I’m happy to present a new iteration in the series:
HammerSpoon-HX.
You can find it here:

What is this? Well, as simple as Haxe bindings for the Lua API of Hammerspoon.
What is Hammerspoon then? Hammerspoon is probably the coolest thing you can install in your MacOS. It provides a Lua API to interact with any system API of OSX, allowing you to control windows (open, close, move, tile…), click on menus, add items to the menu-bar, show contextual menus, take screenshots, write on screen, show notifications and a large etc, you get the idea.
Why is this bindings needed you may ask? Well, Lua is a perfectly valid scripting language, and I have been using it for my personal configuration. However, when I started to build my first Spoon (AKA plugin) it started to show the common problems. My Spoon (StreamDeckButton.spoon) is relatively complex: has subscribers, events, JSON, object parsing, errors, etc, and I already introduced a couple of bugs into it because using the wrong types in the wrong places, the usual problem with untyped languages. On top of that, Spooons are a lot more limited than your normal configuration in terms of code modularity: you can not use import, and you have to do not comfortable dofile imports, this defeats any type inference the lua LSP could do and makes any import another point of failure because nothing validates your path. On top of that, you can not depend ond third party libraries, so you have to implement all yourself. That makes Haxe greatly shine in this scenario: strongly typed and everything compiles down to a single file, so you don’t have to care about imports or third party dependencies,Haxe is fantastic for this.
This doesn’t mean you should use this only for Spoons, you can use it for personal configurations too, but it doesn’t offer that many advantages if your config is simple enough.
As always, comments, pull request and constructive criticism is welcome.
I want to thankt he creator of the Haxe github action, which allows me to easily maintain several haxe libraries with automatic versioning and changelog generation, :heart:

4 Likes