Thanks to visit codestin.com
Credit goes to github.com

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

LuaCheck 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 or Headphones

Automatically switches from AirPods / Headphones connection to Multi-Output Audio Device and Blackhole input to be able to Shazam songs while watching a movie or TV show on AirPods / Headphones.

You will need to install the Blackhole audio driver and set up a Midi Multi-Output Audio device too.

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

If you set your Sound output to the in-built Mac Speaker then the code resets the mic to use the standard Mac built-in Mic to keep the input and output aligned in an intuitive way.

If you set your Sound output to any device with Multi-Output or Blackhole in the name then automatically switches to the Blackhole input for the loop shazamming trick.

Auto-run Speed Test when connecting to a Wifi network

TODO

Modular Structure

The top level init.lua is the entry point that imports the rest of the code structured thus:

$ tree -P '*.lua' --prune
.
├── audio
│   ├── devices.lua
│   ├── switch.lua
│   └── watcher.lua
├── init.lua
└── utils
    └── notify.lua

3 directories, 5 files

More Core Repos

Knowledge

Knowledge-Base Diagrams-as-Code

DevOps Code

DevOps-Bash-tools DevOps-Python-tools DevOps-Perl-tools DevOps-Golang-tools

Containerization

Kubernetes-configs Dockerfiles

CI/CD

GitHub-Actions Jenkins

Databases - DBA - SQL

SQL-scripts

DevOps Reloaded

HAProxy-configs Terraform Packer Ansible Environments

Monitoring

Nagios-Plugins Nagios-Plugin-Kafka Prometheus

Templates

Templates Template-repo

Desktop

TamperMonkey Hammerspoon

Spotify

Spotify-tools Spotify-playlists

The rest of my original source repos are here.

Pre-built Docker images are available on my DockerHub and can be re-generated using the my Dockerfiles repo.

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