Mac event driven automation using Hammerspoon.
Hammerspoon is a system event handler for Mac.
The code is written in Lua.
Includes:
- Auto-switching to Multi-Output for Shazaming when connecting headphones
- Automatically running Speed Test when connecting to a wifi network
Install Hammerspoon using Homebrew:
brew install hammerspoon --caskmkdir -p -v ~/githubgit clone https://github.com/HariSekhon/Hammerspoon ~/github/hammerspoonln -svFhw ~/github/hammerspoon ~/.hammerspoonOutput:
/Users/hari/.hammerspoon -> /Users/hari/github/hammerspoon
Finally, start Hammerspoon, you should see its icon in the menu bar.
open -a HammerspoonSet Hammerspoon to start at login (you can tick this in the Hammerspoon Preferences UI) or just run this:
osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/Hammerspoon.app", hidden:false}'Optionally allow pop-up desktop notifications from Hammerspoon so that your code can notify you when it's done something for you (I recommend Banners that automatically disappear without having to click them).
System Settings -> Notifications ->Hammerspoon:
open "x-apple.systempreferences:com.apple.Notifications-Settings.extension?bundleId=org.hammerspoon.Hammerspoon"Automatically switches from AirPods connection to Multi-Output Audio Device and Blackhole input to be able to Shazam songs while watching a movie or TV show on AirPods.
You will need to install the Blackhole audio driver and set up a Midi Multi-Output Audio device too.
If using headphones other than AirPods you can simply edit the matching line in the code:
if current:match("AirPods") thenSee HariSekhon/Knowledge-Base - Audio page section for more details on this setup.
TODO + refactor
The rest of my original source repos are here.
Pre-built Docker images are available on my DockerHub.