Skip to content

Instantly share code, notes, and snippets.

@alexx855
Created October 3, 2026 13:53
Show Gist options
  • Select an option

  • Save alexx855/3932ddda7fee5b967776890155c62e5c to your computer and use it in GitHub Desktop.

Select an option

Save alexx855/3932ddda7fee5b967776890155c62e5c to your computer and use it in GitHub Desktop.
Chrome new tab to the right on Mac with Hammerspoon (Cmd-T)

Chrome new tab to the right on Mac

Use Hammerspoon to make Cmd-T open and select a tab immediately after the active tab in Google Chrome. The shortcut is enabled only while Chrome is active. The + button keeps its usual behavior.

With B selected:

Before: A | B | C
Cmd-T:  A | B | New | C

Save chrome-tabs.lua in ~/.hammerspoon/, then add this line to your existing init.lua:

dofile(hs.configdir .. "/chrome-tabs.lua")

Choose Hammerspoon → Reload Config. If macOS asks, allow Hammerspoon to control Chrome.

Lua handles the shortcut. The string inside hs.osascript.applescript([[ ... ]]) is AppleScript that creates and selects the tab.

Verified on Mac: adjacent tab placement, another opening after reloading, and disabling outside Chrome.

English note · Nota en español

-- Chrome: Cmd-T opens and selects a tab immediately after the active tab.
local chromeBundleID = "com.google.Chrome"
local log = hs.logger.new("chrome-tabs", "info")
chromeNewTabHotkey = hs.hotkey.new({"cmd"}, "t", function()
local ok, _, details = hs.osascript.applescript([[
tell application "Google Chrome"
if (count of windows) = 0 then
make new window
else
tell front window
set currentIndex to active tab index
make new tab at after tab currentIndex with properties {URL:"chrome://newtab/"}
set active tab index to currentIndex + 1
end tell
end if
end tell
]])
if not ok then
log.e(hs.inspect(details))
hs.alert.show("No se pudo abrir la pestaña de Chrome. Consulta la consola de Hammerspoon.")
end
end)
local function updateHotkey()
local app = hs.application.frontmostApplication()
if app and app:bundleID() == chromeBundleID then
chromeNewTabHotkey:enable()
else
chromeNewTabHotkey:disable()
end
end
-- Retain the watcher and hotkey across garbage collection.
chromeTabWatcher = hs.application.watcher.new(function(_, event)
if event == hs.application.watcher.activated
or event == hs.application.watcher.deactivated then
updateHotkey()
end
end)
chromeTabWatcher:start()
updateHotkey()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment