Hammerspoon is a multi-purpose utility for MacOS. It allows scripting actions with Lua, and low level access to MacOS components.

It can be controlled from the command line by requiring the ipc module in init.lua

init.lua

require("hs.ipc")

Then call this one time from the hammerspoon console: hs.ipc.cliInstall(). Then you can use it at CLI like

hs -c "spoon.GlobalMute:toggle()"