Focus-follows-mouse (plus auto-raise) on Mac OS X

MacosFocusMouse

Macos Problem Overview


(I don't want to hear about how crazy I am to want that! :)

Focus-follows-mouse is also known as point-to-focus, pointer focus, and (in some implementations) sloppy focus. [Add other terms that will make this more searchable!] X-mouse

Macos Solutions


Solution 1 - Macos

You can do it for Terminal.app by issuing the following command at the command line:

defaults write com.apple.Terminal FocusFollowsMouse -bool true

For X11 apps you can do this:

defaults write com.apple.x11 wm_ffm -bool true

In Snow Leopard, use this instead:

defaults write org.x.X11 wm_ffm -bool true

Apparently there's a program called CodeTek Virtual Desktop that'll emulate it systemwide, but it costs $$ (and they never got a version out for OSX Leopard).

Solution 2 - Macos

Steve Yegge wrote an essay about this a while back, where he tried and failed to write a suitable extension. I've since tried to find focus-follows-mouse applications for OS X and failed also.

Solution 3 - Macos

Although this is far from a complete solution, two handy actions that are built into OSX (10.11) are:

⌃⌥-click (control-option-click) - switches focus without raising window

⌘-click (command-click) - clicks in window without switching focus

Not sure when these shortcuts were introduced, as I haven't been able to find them written about anywhere.

Solution 4 - Macos

Focus-follows-mouse is not a particularly suitable input method for OS X because its menu bar was designed to be at the top of the screen. When you move the mouse out of your application window to get to the menus, if it crosses any other application's windows on the way, the menu changes.

So yes, in reply to dreeves comment, it works perfectly fine for Terminal (or for any other single application on the desktop), because the only other windows it's going to affect are Terminal windows, so the menu never changes as you switch windows. And it works fine for X11 because X11 apps generally have their menu bars embedded in the window, so you don't have to leave the window to access them.

Of course you can work around the menu-changing issue by introducing an artificial delay before the focus changes and/or the menu switches, but it's never going to work as well as it does on other desktops.

Solution 5 - Macos

I've been coming back to this question periodically for about 10 years and I finally found a simple solution: AutoRaise https://github.com/sbmpost/AutoRaise

By default it enables focus-follows-mouse AND autoraise. You can delay the autoraise with a config option.

It also has what they call "warp" function that centers the mouse pointer in a window when you Command-Tab to the window. I never knew I needed this until I tried it, but once I tried it, I can't live without it!

Solution 6 - Macos

So I decided to improve again on the work I did on the MouseFocus.app which still had some flaws. Those are fixed now. I renamed the whole thing to "AutoRaise" to better reflect what this tool does: When you hover a window it will be raised to the front (with a delay of your choosing) and gets the focus. The tool can be downloaded here. To use it, copy it to your /Applications/ folder making sure it is executable (chmod 700 AutoRaise). Then double click it from within Finder. To quickly toggle it on/off you can use the applescript below and paste it into an automator service workflow. Then bind the created service to a keyboard shortcut via System Preferences|Keyboard|Shortcuts.

Update (29-03-2017): The AutoRaise binary has been updated. If no delay has been specified on the command line, it will now also look for an AutoRaise.delay file in the same home folder. This is particularly useful when using the applescript below because 'launch application' does not support command line arguments. The delay should be specified in units of 50ms 20ms. For example to specify a delay of 20ms run this command once in a terminal: 'echo 1 > ~/AutoRaise.delay'

on run {input, parameters}
    tell application "Finder"
	    if exists of application process "AutoRaise" then
		    quit application "/Applications/AutoRaise"
		    display notification "AutoRaise Stopped"
	    else
		    launch application "/Applications/AutoRaise"
		    display notification "AutoRaise Started"
	    end if
    end tell
    return input
end run

Update (18-04-2019): The source https://github.com/sbmpost/AutoRaise

Update (05-06-2020): The default delay has been set to 2 and polling time was reduced. These settings prevent unintended window raising when moving the mouse quickly (to reach the top menu for instance). Also a warp mouse feature has been added and a memory leak has been fixed. For further details check out the README

Solution 7 - Macos

The menu issue is the only reason traditional focus-follows-mouse wouldn't work.

Here's an alternative: don't change focus until a key is pressed on the keyboard. This would cover 95% of use cases for focus-follows-mouse, and would make this old curmudgeonly X user really happy. I don't know how many times I'll be scrolling through a web page in Chrome, and hit Command-T to open a new tab, and find the tab opening in the Terminal instead. If my brain hasn't picked up on this in 8 months of using a Mac, it never will.

Solution 8 - Macos

Amethyst supports this feature. It can be easily installed with brew install amethyst.

Here's the config file I use. It turns all the features off besides focus-follows-mouse. Save it to ~/.amethyst.

{
    "LAYOUTS": "----------------------",
    "layouts": [
    ],

    "MODIFIERS": "----------------------",
    "Valid modifiers are": [
        "option",
        "shift",
        "control",
        "command"
    ],

    "mod1": [
    ],
    "mod2": [
    ],

    "COMMANDS": "----------------------",
    "Commands are": {
        "cycle-layout": "Cycle layout to the next layout",
        "cycle-layout-backward": "Cycle layout to the previous layout",
        "focus-screen-1": "Focus the main window on the first screen",
        "focus-screen-2": "Focus the main window on the second screen",
        "focus-screen-3": "Focus the main window on the third screen",
        "focus-screen-2": "Focus the main window on the second screen",
        "focus-screen-3": "Focus the main window on the third screen",
        "focus-screen-4": "Focus the main window on the fourth screen",
        "throw-screen-1": "Throw the focused window to the first screen",
        "throw-screen-2": "Throw the focused window to the second screen",
        "throw-screen-3": "Throw the focused window to the third screen",
        "throw-screen-4": "Throw the focused window to the fourth screen",
        "shrink-main": "Shrink the main pane of the current layout",
        "expand-main": "Expand the main pane of the current layout",
        "increase-main": "Increase the number of windows in the main pane",
        "decrease-main": "Decrease the number of windows in the main pane",
        "focus-ccw": "Move window focus counter-clockwise on the current screen",
        "focus-cw": "Move window focus clockwise on the current screen",
        "swap-ccw": "Swap focused window with the next window going counter-clockwi$
        "swap-cw": "Swap focused window with the next window going clockwise",
        "swap-main": "Swap focused window with the main window of its screen",
        "throw-space-1": "Throw the focused window to the first space",
        "throw-space-2": "Throw the focused window to the second space",
        "throw-space-3": "Throw the focused window to the third space",
        "throw-space-4": "Throw the focused window to the fourth space",
        "throw-space-5": "Throw the focused window to the fifth space",
        "throw-space-6": "Throw the focused window to the sixth space",
        "throw-space-7": "Throw the focused window to the seventh space",
        "throw-space-8": "Throw the focused window to the eighth space",
        "throw-space-9": "Throw the focused window to the ninth space",
        "throw-space-8": "Throw the focused window to the eighth space",
        "throw-space-9": "Throw the focused window to the ninth space",
        "toggle-float": "Toggle the focused window between being floating and tiled"
    },

    "screens": "3",

    "cycle-layout": {
        "mod": "mod1",
    },
    "cycle-layout-backward": {
        "mod": "mod2",
    },
    "select-tall-layout": {
        "mod": "mod1"
    },
    "select-wide-layout": {
        "mod": "mod1"
    },
    "select-fullscreen-layout": {
        "mod": "mod1"
    },
    "select-column-layout": {
        "mod": "mod1"
    },
        "mod": "mod1"
    },
    "focus-screen-1": {
        "mod": "mod1"
    },
    "focus-screen-2": {
        "mod": "mod1"
    },
    "focus-screen-3": {
        "mod": "mod1"
    },
    "focus-screen-4": {
        "mod": "mod1"
    },
    "throw-screen-1": {
        "mod": "mod2"
    },
    "throw-screen-2": {
        "mod": "mod2"
    },
    "throw-screen-3": {
        "mod": "mod2"
    },
    "throw-screen-4": {
        "mod": "mod2"
    "throw-screen-4": {
        "mod": "mod2"
    },
    "shrink-main": {
        "mod": "mod1"
    },
    "expand-main": {
        "mod": "mod1"
    },
    "increase-main": {
        "mod": "mod1"
    },
    "decrease-main": {
        "mod": "mod1"
    },
    "focus-ccw": {
        "mod": "mod1"
    },
    "focus-cw": {
        "mod": "mod1"
    },
    "swap-screen-ccw": {
        "mod": "mod2"
    },
    "swap-screen-cw": {
    },
    "swap-screen-cw": {
        "mod": "mod2"
    },
    "swap-ccw": {
        "mod": "mod2"
    },
    "swap-cw": {
        "mod": "mod2"
    },
    "swap-main": {
        "mod": "mod1"
    },
    "throw-space-1": {
        "mod": "mod2"
    },
    "throw-space-2": {
        "mod": "mod2"
    },
    "throw-space-3": {
        "mod": "mod2"
    },
    "throw-space-4": {
        "mod": "mod2"
    },

        "mod": "mod2"
    },
    "throw-space-5": {
        "mod": "mod2"
    },
    "throw-space-6": {
        "mod": "mod2"
    },
    "throw-space-7": {
        "mod": "mod2"
    },
    "throw-space-8": {
        "mod": "mod2"
    },
    "throw-space-9": {
        "mod": "mod2"
    },
    "toggle-float": {
        "mod": "mod1"
    },
    "toggle-tiling": {
        "mod": "mod2"
    },
    "display-current-layout": {
        "mod": "mod1"
    "display-current-layout": {
        "mod": "mod1"
    },

    "MISC": "----------------------",
    "floating": [],
    "float-small-windows": false,
    "mouse-follows-focus": false,
    "focus-follows-mouse": true,
    "enables-layout-hud": false,
    "enables-layout-hud-on-space-change": false
}

Solution 9 - Macos

Focus follows mouse is now possible in macOS, Mojave in my case, using chunkwm. See this Stack Overflow response for a "no autoraise" solution. Autoraise is activated by leaving

chunkc set ffm_disable_autoraise         0

in ~/.chunkwmrc.

Edit 2019-09-12:

chunkwm has been superseded by yabai. To install:

brew tap koekeishiya/formulae
brew install yabai
mkdir -p ~/.config/yabai/
printf 'yabai -m config focus_follows_mouse autoraise' >> ~/.config/yabai/yabairc
brew services start yabai

Solution 10 - Macos

Codetek had a product that did this but they never released a version for Leopard or later.

MondoMouse can sort of do focus-follows-mouse, but not auto-raise. Even the focus-follows-mouse is broken though. For example, it doesn't play well with command-tab (if you command-tab to a new application and don't touch the mouse then it should not switch focus back to wherever the mouse pointer happens to be -- I'm pretty sure every implementation in Linux I've seen gets this right but MondoMouse doesn't).

You can enable focus-follows-mouse (no autoraise) for just Terminal windows (just execute the following in a terminal):

defaults write com.apple.Terminal FocusFollowsMouse -string YES

And similarly for X11 windows:

defaults write org.x.X11 wm_ffm -bool true 

(For mac versions previous to 10.5.5 this was:

defaults write com.apple.x11 wm_ffm true

)

I don't know of any other applications that support it.

Solution 11 - Macos

I currently use MondoMouse and even with its quirks I couldn't use my mac without it. They have a free trial and I would recommend it to everyone.

MondoMouse

Solution 12 - Macos

chunkwm supports this too (by default I believe): chunkwm

Solution 13 - Macos

Interesting that Leopard has one flavor of focus-follows-mouse (sans autoraise) enabled by default. The scroll wheel works in unfocused windows.

Solution 14 - Macos

Unfortunately CodeTek Virtual Desktop Pro is no longer developed, and the company seems to have gone out of business a few years back..

Historic reference: http://www.codetek.com/ctvd/ (does not work on new OS X versions!)

Historic review: http://www.osnews.com/story/6144

Using CodeTek Virtual Desktop Pro you were able to get Focus-Follow-Mouse and disable Auto-Raise, and it also had a Pager for the virtual desktops -- similar to how Fvwm works on Linux. It really worked perfectly -- the best piece of software that I've ever bought. It worked consistently with all apps, and switching apps, moving windows to different workspaces, and navigating workspaces worked much easier than how it is implemented in the latest OS X versions [10.6, 10.7, 10.8]

Unfortunately with Mac OS X 10.5 VirtualDesktop Pro stopped working, and it looks like Apple actively made sure that CodeTek will not continue to work on it.

It is sad that Apple crushed CodeTek and it's product - Virtual Desktop Pro was really superior to how OS X workspaces are currently implemented. It worked basically like Fvwm on LINUX - super fast navigation -- without unnecessary clicks or mouse gestures...

It saddens me to see that Apple dictates window manager (Finder) behavior and does not seem to allow third-party replacements for the Finder anymore.

Solution 15 - Macos

There is also the related issue of raise-on-click. Under OSX each time a window is clicked, it is also raised, thus potentially hiding other windows. This is problematic when working with copy/paste from two windows where one of them covers most of the screen. I like to keep a global (active in all workspaces) notepad from which I copy/paste stuff (could be anything from commands, text, todo items etc). This is challenging under OSX. It would be nice to have an option to disable raise-on-click.

Solution 16 - Macos

Give DwellClick a try. Although, it's not for its intended purpose, the auto-click behavior has a side effect similar to auto-raise or focus-follows-mouse.

Personally, I only use the feature of left clicking after my cursor movement comes to rest, but there's also clicking with modifiers and a window dragging assist that's quite handy.

It's also a little frustrating while web browsing since you'll either want to disable the app or be more conscious of where the cursor rests (e.g. not on any links or buttons you don't intend to activate).

Solution 17 - Macos

Use Dwell feature in mac. Go to Accessibility -> keyboard -> Accessibility keyboard (I'm on Catalina)

Click here for more info


enter image description here

enter image description here

Solution 18 - Macos

Experimenting with those options, my Command-Tab started to behave oddly. Here is the solution of how it gives focus to apps again:

It appears that a previous feature, namely the ability for Terminal's window focus to change with mouse movement, is broken in 10.6 and causes Command-Tab to not transfer window focus correctly. To fix the problem, just paste the following command in a Terminal:

defaults write com.apple.Terminal FocusFollowsMouse -string NO

Then restart Terminal.

Solution 19 - Macos

Solution: Because I was so used to autoraise in Windows I badly missed it on the Mac. The solution I found for the Mac is Zooom (yes, three o's). It has an autoraise function. You can even set milliseconds to wait before autoraise. Can't live without it. Autoraise is an option in prefs as you can see in the screenshot https://www.macupdate.com/app/mac/23203/zooom http://coderage-software.com/zooom/index.html

Solution 20 - Macos

Some potentially useful advice for part "focus on hover" with dual screens. It doesn't fix some things like typing into an input box when another screen already has input box focus. But it might help people who come here for all aspects of "focus on hover".

Without this fix I always had to "focus click" in a monitor before I can contextually click on anything at all.

You can get some aspects of "focus on hover" with this:

  1. Go into 'System Preferences'
  2. Select option 'Mission Control'
  3. In there you should see 'Displays have separate Spaces', untick it

Then at least with Monitor1 selected, now you can instantly click on something in Monitor2, like an email or Tab, without needing the first "focus click".

As always can be the case, this may not work for everyone depending on OS version and probably other things.

Solution 21 - Macos

Tested MondoMouse (https://www.atomicbird.com/about/mac-apps) on MacOS Mojave. Seems to work fine for me!

To install the prefpane, there will be a notice "enable access for assistive devices" that does not reside in the System Preferences > Accessibility anymore. You'll have to set it in Security & Privacy > Accessibility > Privacy

There will be several warnings about allowing MondoMouse in each app you have open, but once set it works fine! What a relief :)

Solution 22 - Macos

Here's a working toy-level implementation for multi-monitor autofocus if anyone is interested: https://bitbucket.org/sivann/mac-screenfocus/src/master/

It mostly works, but does not handle multiple windows of the same app in different monitors. Gives focus to the last app that had it if you move the mouse to another monitor.

Solution 23 - Macos

You can't really do it well, because the Mac interface simply isn't designed with focus-follows-mouse (with or without auto-raise) in mind. I doubt that's going to change any time soon, and unless it does, everybody who tries to implement focus-follows-mouse will run into the same hurdles and wind up with an unsatisfactory result (to those who want such a thing).

So, yes, you are crazy for wanting this — but for technical reasons. Get used to using the Mac on its own terms and I'm sure your desire to force it to behave just like whatever X11 stuff you used to use will subside in a bit as you find new efficient ways of working.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondreevesView Question on Stackoverflow
Solution 1 - MacosClint EckerView Answer on Stackoverflow
Solution 2 - MacosJohn MillikinView Answer on Stackoverflow
Solution 3 - MacosdvjView Answer on Stackoverflow
Solution 4 - Macoscalum_bView Answer on Stackoverflow
Solution 5 - MacosGareth JamesView Answer on Stackoverflow
Solution 6 - MacossbmpostView Answer on Stackoverflow
Solution 7 - MacosKyle RoseView Answer on Stackoverflow
Solution 8 - MacoswprlView Answer on Stackoverflow
Solution 9 - MacosLes GrieveView Answer on Stackoverflow
Solution 10 - MacosdreevesView Answer on Stackoverflow
Solution 11 - MacosmcottonView Answer on Stackoverflow
Solution 12 - MacosasselinpaulView Answer on Stackoverflow
Solution 13 - Macosck_View Answer on Stackoverflow
Solution 14 - MacosTiloView Answer on Stackoverflow
Solution 15 - MacossfarView Answer on Stackoverflow
Solution 16 - MacosBen MView Answer on Stackoverflow
Solution 17 - MacoscherankrishView Answer on Stackoverflow
Solution 18 - MacosTeam PannousView Answer on Stackoverflow
Solution 19 - MacosGary KaputnikView Answer on Stackoverflow
Solution 20 - MacosJamesView Answer on Stackoverflow
Solution 21 - MacosMaltaCodeView Answer on Stackoverflow
Solution 22 - MacossivannView Answer on Stackoverflow
Solution 23 - MacosChris HansonView Answer on Stackoverflow