keepcalculator

06 Numbers and Powers

Terminal Focus Follow Mouse Mac? Explained

Card No. 06·77240 · Updated · Standard formula, shown below

Yes, macOS Terminal can be made to follow the mouse cursor for focus, but it is not a built-in setting. You can achieve this behavior using a third-party tool like Karabiner-Elements or Hammerspoon, or by enabling the system-wide “Focus follows mouse” accessibility option (which affects all apps, not just Terminal). This article explains what “focus follows mouse” means for Terminal, why it is not a default option, and how to set it up safely.

What Does “Focus Follows Mouse” Mean?

In most macOS apps, the window that has “focus” is the one you click on. With focus-follows-mouse (also called “sloppy focus” or “pointer focus”), the window under your cursor automatically becomes active without a click. This is a common feature in Unix-like environments and window managers (e.g., X11, i3, Sway) and is often preferred by developers who want to type in a window without moving the mouse to click it.

For Terminal specifically, enabling focus-follows-mouse means that when you move your mouse over a Terminal window, it becomes the active window and receives keystrokes immediately—no click required. This can speed up workflows when working with multiple terminal windows or when using a tiling window manager.

Why Isn’t It Built-In?

Apple’s macOS has historically favored a click-to-focus model for desktop usability. The Terminal app itself does not expose a focus-follows-mouse preference. However, macOS does have a hidden accessibility setting called “Focus follows mouse” (under System Settings > Accessibility > Pointer Control). When enabled, this applies system-wide—every window under the cursor becomes active. It works with Terminal, but it also affects all other apps, which can be disorienting (e.g., a browser window might steal focus while you’re typing in a text editor).

Because that system-wide option is blunt, many users prefer a per-app solution. That’s where third-party tools come in.

How to Enable It with Karabiner-Elements

Karabiner-Elements is a powerful keyboard customization tool that can also manipulate mouse focus. To set up focus-follows-mouse for Terminal only:

  1. Install Karabiner-Elements from karabiner-elements.pqrs.org (it’s free and open-source).
  2. Open Karabiner-Elements and go to the Complex Modifications tab.
  3. Click Add rule and search for “focus follows mouse”—you’ll find a rule that enables it for all apps or specific ones.
  4. If you want Terminal only, edit the rule’s JSON to restrict it to com.apple.Terminal.
  5. Enable the rule. The change takes effect immediately.

Karabiner-Elements works by simulating mouse events and modifying window focus behavior. It’s widely used, but it requires giving it accessibility permissions in System Settings > Privacy & Security > Accessibility.

How to Enable It with Hammerspoon

Hammerspoon is a scripting tool for macOS that lets you automate actions with Lua scripts. A simple script can make Terminal focus follow the mouse:

-- Focus follows mouse for Terminal only
local function focusTerminal()
  local win = hs.window.focusedWindow()
  if win then
    win:setFrame(win:frame()) -- no-op to keep focus
  end
end

-- Watch mouse moves and activate Terminal if cursor is over it
hs.loadSpoon("MouseFollowsFocus")
spoon.MouseFollowsFocus:start()

However, a more reliable approach is to use the hs.window.filter to detect when the mouse enters a Terminal window and then call hs.window:focus(). Here’s a minimal working script:

hs.window.filter.new():subscribe(hs.window.filter.windowMoved, function()
  local win = hs.window.focusedWindow()
  if win and win:application():name() == "Terminal" then
    win:focus()
  end
end)

This script is more complex but gives you full control. Hammerspoon also requires accessibility permissions.

Using the System-Wide Option (Simplest)

If you want a quick, no-install solution, enable the system-wide focus-follows-mouse:

  1. Open System Settings (Apple menu > System Settings).
  2. Go to Accessibility > Pointer Control.
  3. Turn on “Focus follows mouse”.

This works for Terminal immediately, but be prepared for every window to steal focus as you move the mouse. Many users find this annoying because it makes it hard to scroll a web page without accidentally typing in a different window. If you only need it for Terminal, the third-party tools are better.

Common Problems and Troubleshooting

  • Focus doesn’t change until you click: If you enabled the system option and it still doesn’t work, check that you haven’t enabled “Disable automatic window tabbing” or that your mouse driver isn’t overriding it.
  • Karabiner rule doesn’t appear: Make sure you’ve added the rule from the Complex Modifications tab, and that Karabiner-Elements is running (check the menu bar icon).
  • Hammerspoon script errors: Ensure you’ve installed the MouseFollowsFocus spoon via hs.ipc or manually. A simpler script is to use hs.window.filter as shown above.
  • Focus follows mouse but Terminal doesn’t receive keystrokes: This can happen if Terminal is in “Secure Keyboard Entry” mode (View > Secure Keyboard Entry). Turn that off.
  • It works but is too sensitive: Some tools allow a delay. Karabiner’s rule doesn’t include a delay, but you can edit the JSON to add a condition based on mouse position or time.

Alternatives: Terminal Multiplexers and Tiling

If your goal is efficient multi-window terminal work, consider using a terminal multiplexer like tmux or screen. These let you split one Terminal window into multiple panes, each with its own shell, and you can switch between panes with keyboard shortcuts (e.g., Ctrl+B, then arrow keys). This avoids the need for focus-follows-mouse entirely.

Another alternative is to use a tiling window manager like yabai (which also works with Hammerspoon) to automatically arrange windows and manage focus. yabai can be configured to focus windows on mouse hover, but it’s more complex to set up.

Frequently Asked Questions

Does macOS Big Sur or Monterey support focus follows mouse natively?

Yes, the system-wide accessibility option exists in all recent macOS versions (Big Sur, Monterey, Ventura, Sonoma). It’s under System Settings > Accessibility > Pointer Control. It works for Terminal, but it’s all-or-nothing.

Will focus follows mouse work with iTerm2?

Yes, the system-wide option works with iTerm2 as well. iTerm2 also has its own setting: Preferences > General > Window > “Focus follows mouse” (or “Activate on mouse over”). This is a built-in feature in iTerm2, so you don’t need third-party tools if you use iTerm2.

Is there a way to make only Terminal follow the mouse without affecting other apps?

Yes, use Karabiner-Elements or Hammerspoon as described above. These tools can restrict the behavior to Terminal only by checking the application name or bundle identifier.

Does enabling focus follows mouse slow down my Mac?

No, the system-wide option is lightweight. Karabiner-Elements and Hammerspoon run in the background and may use a small amount of CPU, but the impact is negligible on modern hardware.

Can I set a delay before focus changes?

With Hammerspoon, you can add a timer to delay the focus change. For example, wait 0.2 seconds after the mouse enters a window before focusing it. Karabiner’s built-in rule doesn’t have a delay option, but you can edit the JSON to add a condition based on time.

Is focus follows mouse safe to use?

Yes, it’s a standard accessibility feature. However, granting accessibility permissions to third-party tools like Karabiner or Hammerspoon means those apps can control your computer. Download them only from official sources and review their code if you’re concerned.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →