Last active
October 21, 2025 09:56
-
-
Save chris-kobrzak/c8c780ab579976356d9f0c4606b854a7 to your computer and use it in GitHub Desktop.
Hammerspoon script enabling a Mac Shortcuts workflow when an external monitor gets connected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Mac Shortcuts workflow name | |
| local workflowName = "Home Bluetooth" | |
| hs.logger.defaultLogLevel = "info" | |
| local log = hs.logger.new("DisplayWatcher", "info") | |
| local function runWorkflowIfExternalDisplay() | |
| local hasExternal = false | |
| for _, screen in ipairs(hs.screen.allScreens()) do | |
| if screen:name() ~= "Built-in Retina Display" then | |
| hasExternal = true | |
| break | |
| end | |
| end | |
| if not hasExternal then | |
| return | |
| end | |
| log.i("External display detected. Running Shortcuts workflow in 5 seconds...") | |
| hs.timer.doAfter(5, function() | |
| log.i("Executing workflow...") | |
| hs.execute('shortcuts run "' .. workflowName .. '"') | |
| end) | |
| end | |
| hs.screen.watcher.new(function() | |
| runWorkflowIfExternalDisplay() | |
| end):start() | |
| log.i("Hammerspoon display watcher started.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| brew install hammerspoon | |
| open /Applications/Hammerspoon.app | |
| -- Consider enabling `Launch Hammerspoon at login` in app settings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment