Created
July 28, 2025 23:16
-
-
Save ther0y/684f902bb6e1bdf96baecce2897a158d to your computer and use it in GitHub Desktop.
Instant Profile (windows) Switching for Dia Browser using Hammerspoon
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
--[[ | |
Dia Profile Switcher for macOS using Hammerspoon | |
------------------------------------------------ | |
This script allows instant switching between Dia browser profiles (e.g. Work and Personal) | |
by detecting pinned tab titles in each window using macOS Accessibility APIs. | |
It caches matched windows for fast reuse, and falls back to scanning tabs if the window is closed or lost. | |
]] | |
local cachedDiaWindows = {} | |
local function focusDiaByPinnedTab(tabName) | |
-- Try cached | |
local cached = cachedDiaWindows[tabName] | |
if cached and cached:isVisible() and cached:title() ~= "" then | |
cached:focus() | |
return | |
end | |
-- Fallback to AX-based scan for pinned tab with matching title | |
for _, win in ipairs(hs.window.filter.new("Dia"):getWindows()) do | |
local axWin = hs.axuielement.windowElement(win) | |
if not axWin then goto continue end | |
local children = axWin.AXChildren or {} | |
for _, child in ipairs(children) do | |
if child:attributeValue("AXRole") == "AXGroup" then | |
local subChildren = child:attributeValue("AXChildren") or {} | |
for _, tab in ipairs(subChildren) do | |
local title = tab:attributeValue("AXTitle") | |
if title == tabName then | |
cachedDiaWindows[tabName] = win | |
win:focus() | |
return | |
end | |
end | |
end | |
end | |
::continue:: | |
end | |
hs.alert("No Dia window with pinned tab: " .. tabName) | |
end | |
-- Hotkeys: Switch between Dia profiles by detecting pinned tab titles | |
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "W", function() | |
focusDiaByPinnedTab("CUSTOM TAB NAME") | |
end) | |
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "P", function() | |
focusDiaByPinnedTab("CUSTOM TAB NAME") | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment