Last active
December 22, 2025 22:08
-
-
Save overset/d6530bf528492baf9949c13102f3ca37 to your computer and use it in GitHub Desktop.
Hammerspoon Config: 3 column + 2 row tiling, Apple Music control (stop/play, fwd/back, volume)
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
| -- window tiling for 3 col + 2 row | |
| function tile(x_pos, y_pos) | |
| return function() | |
| local win = hs.window.focusedWindow() | |
| local f = win:frame() | |
| local screen = win:screen() | |
| local max = screen:frame() | |
| local new_width = max.w / 3 | |
| local new_height = max.h / 2 | |
| f.x = new_width * x_pos | |
| f.y = new_height * y_pos + (y_pos > 0 and 26 or 0) | |
| f.w = new_width | |
| f.h = new_height | |
| win:setFrame(f, 0) | |
| end | |
| end | |
| hs.hotkey.bind({"alt"}, "4", tile(0, 0)) | |
| hs.hotkey.bind({"alt"}, "5", tile(1, 0)) | |
| hs.hotkey.bind({"alt"}, "6", tile(2, 0)) | |
| hs.hotkey.bind({"alt"}, "1", tile(0, 1)) | |
| hs.hotkey.bind({"alt"}, "2", tile(1, 1)) | |
| hs.hotkey.bind({"alt"}, "3", tile(2, 1)) | |
| -- This manually toggles play/pause on Apple Music.app | |
| function apple_music_playback() | |
| hs.application.launchOrFocus("Music") | |
| local aapl_music = hs.appfinder.appFromName("Music") | |
| local str_pause = {"Controls", "Pause"} | |
| local str_play_and_pause = {"Controls", "Play"} | |
| local pause = aapl_music:findMenuItem(str_pause) | |
| local play_and_pause = aapl_music:findMenuItem(str_play_and_pause) | |
| if (pause) then | |
| aapl_music:selectMenuItem(str_pause) | |
| end | |
| if (play_and_pause) then | |
| aapl_music:selectMenuItem(str_play_and_pause) | |
| end | |
| end | |
| hs.hotkey.bind({}, 'f8', apple_music_playback) | |
| -- Volume Control in Apple Music.app | |
| function apple_music_volume(direction) | |
| return function() | |
| hs.application.launchOrFocus("Music") | |
| local aapl_music = hs.appfinder.appFromName("Music") | |
| aapl_music:selectMenuItem({"Controls", direction}) | |
| end | |
| end | |
| hs.hotkey.bind({"cmd", "ctrl"}, 'up', apple_music_volume("Increase Volume")) | |
| hs.hotkey.bind({"cmd", "ctrl"}, 'down', apple_music_volume("Decrease Volume")) | |
| -- Hotkey to jump to specific chrome work tabs | |
| function jump_work_tab(name, title) | |
| return function() | |
| local script = ([[(function() { | |
| var browser = Application('%s'); | |
| browser.activate(); | |
| for (win of browser.windows()) { | |
| var tabIndex = | |
| win.tabs().findIndex(tab => tab.title().match(/%s/)); | |
| if (tabIndex != -1) { | |
| win.activeTabIndex = (tabIndex + 1); | |
| win.index = 1; | |
| } | |
| } | |
| })(); | |
| ]]):format(name, title) | |
| hs.osascript.javascript(script) | |
| end | |
| end | |
| hs.hotkey.bind({"cmd", "shift"}, "1", jump_work_tab("Chrome", "Mail")) | |
| hs.hotkey.bind({"cmd", "shift"}, "2", jump_work_tab("Chrome", "Calendar")) | |
| hs.hotkey.bind({"cmd", "shift"}, "3", jump_work_tab("Chrome", "Slack")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment