Automate Tasks with Hammerspoon
·
1 min read
·
170
Words
·
-Views
-Comments
I’d heard of Hammerspoon but hadn’t tried it. I wrote a few scripts recently — fun and useful — sharing notes here.
Below, hs
stands for Hammerspoon.
A small utility
Features
- Auto‑mute system audio
- Switch MVN settings
Code
-- audio mute
-- change mvn setting
local workWifi = 'company-wifi'
local outputDeviceName = 'Built-in Output'
hs.wifi.watcher.new(function()
local currentWifi = hs.wifi.currentNetwork()
local currentOutput = hs.audiodevice.current(false)
if not currentWifi then return end
if (currentWifi == workWifi and currentOutput.name == outputDeviceName) then
hs.audiodevice.findDeviceByName(outputDeviceName):setOutputMuted(true)
local changeMvnCommand="ln -sfn ~/.m2/settings_company.xml ~/.m2/settings.xml"
hs.execute(shell_command)
hs.notify.new({title="HS Robot", informativeText="Connect to Company"}):send()
end
end):start()
How it differs from Alfred
- Alfred offers fixed interaction patterns (keywords, hotkeys) to boost productivity.
- Hammerspoon uses Lua bindings to macOS APIs for things Alfred can’t do: listen for Wi‑Fi changes, run shell commands, manage windows, etc.
- They complement each other well.
References
For simple tools, the official docs are best: