Put two Chrome tabs side-by-side
Create a hotkey that pops out your current Chrome tab and displays it side-by-side with another.
Next ChapterAPIs used today | Description |
hs.appfinder | Find an application by name. |
hs.application | Query and interact with running applications. |
hs.hotkey | Everything you need to bind functions to hotkeys. |
hs.timer | Precisely control when your code runs, like JS's setTimeout/setInterval . |
What you’re building #
You’re going to use the window management module you made in Chapter 11 to create a hot key that splits two Chrome tabs into 2 side-by-side windows. This is a key I use multiple times daily, as I often want to see 2 tabs at once and I have a wide enough monitor.
Here’s a demo of what it will look like when you’re finished:
Create a new file #
First, make a config file to hold all your code for this project:

touch ~/.hammerspoon/chrome-split.lua
And require it in your main config:

require("chrome-split")
Bind a hotkey #
In the previous chapter, you made a bunch of handy window management functions. You’re going to reuse those functions to make the side-by-side tab viewer.
To achieve this, you need to:
- Move the current window to the left half of the screen
- Pop out the tab into its own window
- Move the popped out tab to the right half of the screen
In addition to reusing window-management.lua
, you’ll use hs.timer.doAfter
to control the timing of when we pop the tab out, so we give the window animations enough time to complete
hs.timer.doAfter
is similar to JavaScript’s setTimeout
–it will run a function after X seconds:

hs.timer.doAfter(2.5, function()
hs.alert.show("We waited 2.5 seconds to run this code.")
end)
As well, you’ll use hs.appfinder
and its selectMenuItem
to programmatically select Chrome’s Move Tab to New Window menu item:

Add this function to your config file:

-- Import the window management functions from the previous chapter.
local wm = require('window-management')
-- Pops the visible Chrome tab into a new browser window next to the current one
local function popoutChromeTabSideBySide()
-- Move current window to the left half
wm.leftHalf()
-- Wait 100ms for the window to move, before popping out the next tab.
hs.timer.doAfter(100 / 1000, function()
-- Focus the Chrome instance if it's not already focused.
hs.application.launchOrFocus('/Applications/Google Chrome.app')
-- Pop out the current tab by selecting the Chrome menu option
local chrome = hs.appfinder.appFromName("Google Chrome")
local moveTab = {'Tab', 'Move Tab to New Window'}
chrome:selectMenuItem(moveTab)
-- Move the popped out tab to the right of the screen
wm.rightHalf()
end)
end
Next, bind the function to a hotkey of your choice. I chose ⌘⌃⌥ ] for mine:

-- Bind this to super + ]
hs.hotkey.bind(super, ']', popoutChromeTabSideBySide)
🎉   And you’re done!
Open work and personal links in different browsers
Get the entire script #
Want to just paste in this whole project to your chrome-split.lua
file?

-- Import the window management functions from the previous chapter.
local wm = require('window-management')
-- Pops the visible Chrome tab into a new browser window next to the current one
local function popoutChromeTabSideBySide()
-- Move current window to the left half
wm.leftHalf()
-- Wait 100ms for the window to move, before popping out the next tab.
hs.timer.doAfter(100 / 1000, function()
-- Focus the Chrome instance if it's not already focused.
hs.application.launchOrFocus('/Applications/Google Chrome.app')
-- Pop out the current tab by selecting the Chrome menu option
local chrome = hs.appfinder.appFromName("Google Chrome")
local moveTab = {'Tab', 'Move Tab to New Window'}
chrome:selectMenuItem(moveTab)
-- Move the popped out tab to the right of the screen
wm.rightHalf()
end)
end
-- Bind this to super + ]
hs.hotkey.bind(super, ']', popoutChromeTabSideBySide)