Hammer. Spoon... Lua?

Ugh
Me, dressed as a Norse God holding a hammer in one hand, and a spoon in the other Source: Apple’s AI Image Playground
Sigh. Lets… just move on.
Hammerspoon
So, in addition to the built-in AppleScript, Automator and, recently, Shortcuts there are other tools that macOS users can use to automate their macs and get things done. One of them is the amazing Hammerspoon.
Despite the weird name, this tool allows you to write Lua scripts to interact with your mac, display dialogs, and handle macOS stuff along with the more traditional unixy stuff that you might associate with Lua. If you’re not aware, Lua is a small language that you can easily embed in many other languages, and as a stand-alone scripting language, it can be used to make quick and easy scripts to do all sorts of things. Notably, Lua is used frequently in game design as a mechanism to allow for scripting or even external plugin infrastructure.
Extending this to macOS lets you do all sorts of things that normally you’d have to reach out into AppleScript territory, or build custom tools to poll the system services to get the information you need. It also allows you to bring in parts of the wider Lua ecosystem to craft what you need. Things like Fennel allow you to write Lisp instead of Lua, if that’s your thing. It all Just Works(tm).
Right now, I’m in the process of working with ChatGPT to build a simple
batch-rename tool in the style of Emacs’ wdired-mode that has you able to edit
the file names in an editor and then have them renamed accordingly. The progress
has been fast and with few actual errors. I’ve been learning how Lua works, and
getting advice on how to build applications in Lua. It’s made me appreciate the
language more than I did before.
Hopefully, once I have something truly working well, I’ll post it here. It’s not too long yet, and it brings in some of the cool tricks that Lua can do without having to puzzle out how to do it in a more complex language like C++ or Objective C.
This is just scratching the surface of the tool. Though, be warned, it’s a steep cliff in terms of learning. When you start it, you have nothing. It expects you to build the parts from the language and it’s extensions.

Comments
Webmentions