Skip to content

Mac event driven automation, eg. auto-run SpeedTest when connecting to Wifi, auto-switch to Multi-Output to Shazam from TV/Movies while listening on headphones

License

Notifications You must be signed in to change notification settings

HariSekhon/Hammerspoon

Repository files navigation

Hari Sekhon - Hammerspoon Mac Event-Driven Automation Code

GitHub stars GitHub forks LineCount Cocomo License My LinkedIn GitHub Last Commit

Codacy CodeFactor Quality Gate Status Maintainability Rating Reliability Rating Security Rating

Mac Lua

CI Builds Overview Azure DevOps Pipeline GitLab Pipeline BitBucket Pipeline

Repo on GitHub Repo on GitLab Repo on Azure DevOps Repo on BitBucket

Markdown Validation Kics Grype Semgrep Semgrep Cloud SonarCloud Trivy

Summary

Mac event driven automation using Hammerspoon.

Hammerspoon is a system event handler for Mac.

The code is written in Lua.

Includes:

Setup

Install Hammerspoon

Install Hammerspoon using Homebrew:

brew install hammerspoon --cask

Add Hammerspoon Code

mkdir -p -v ~/github
git clone https://github.com/HariSekhon/Hammerspoon ~/github/hammerspoon
ln -svFhw ~/github/hammerspoon ~/.hammerspoon

Output:

/Users/hari/.hammerspoon -> /Users/hari/github/hammerspoon

Run Hammerspoon

Finally, start Hammerspoon, you should see its icon in the menu bar.

open -a Hammerspoon

Auto-Start Hammerspoon

Set 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}'

Allow Desktop Notifications

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"

Automation Code

Auto-Switch to Multi-Output to Shazam from TV/Movies while listening on AirPods

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") then

See HariSekhon/Knowledge-Base - Audio page section for more details on this setup.

Auto-run Speed Test when connecting to a Wifi network

TODO + refactor

More Core Repos

Knowledge

Readme Card Readme Card

DevOps Code

Readme Card Readme Card Readme Card Readme Card

Containerization

Readme Card Readme Card

CI/CD

Readme Card Readme Card

Databases - DBA - SQL

Readme Card

DevOps Reloaded

Readme Card Readme Card Readme Card Readme Card Readme Card

Monitoring

Readme Card Readme Card Readme Card

Templates

Readme Card Readme Card

Desktop

Readme Card Readme Card

Spotify

Readme Card Readme Card

The rest of my original source repos are here.

Pre-built Docker images are available on my DockerHub.

About

Mac event driven automation, eg. auto-run SpeedTest when connecting to Wifi, auto-switch to Multi-Output to Shazam from TV/Movies while listening on headphones

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published