Skip to content

Instantly share code, notes, and snippets.

@raxigan
Created March 31, 2022 05:19
Show Gist options
  • Save raxigan/588bb3c97ec2a2a3b3042846fbf7fe51 to your computer and use it in GitHub Desktop.
Save raxigan/588bb3c97ec2a2a3b3042846fbf7fe51 to your computer and use it in GitHub Desktop.
Hammerspoon script to disable Mission Control on macOS
disableTopScreenEdgeForDragging = hs.eventtap.new({ hs.eventtap.event.types.leftMouseDragged }, function(e)
local loc = e:location()
if loc.y == 0.0 then
hs.mouse.setAbsolutePosition({ x = loc.x, y = 0.01 },
1337 -- a hack, do not remove
)
end
end)
disableTopScreenEdgeForDragging:start()
@raxigan
Copy link
Author

raxigan commented Sep 4, 2024

Thanks for sharing the script. Unfortunately I can't get it to work on Sonoma 14.6.1. Any suggestions?

What issue exactly do you have? Isn't it working for you or you have problems to set it up?

In general this script should work. The only problem I'm aware of is when you have 2 or more monitors connected with different resolutions, then it might work only for the main's one top screen edge.

If you provide some more details I'll try to investigate it. Your monitor setup, hammerspoon version, maybe some logs from it, how to reproduce your issue etc.

@homecb
Copy link

homecb commented Sep 4, 2024

Thanks for sharing the script. Unfortunately I can't get it to work on Sonoma 14.6.1. Any suggestions?

What issue exactly do you have? Isn't it working for you or you have problems to set it up?

In general this script should work. The only problem I'm aware of is when you have 2 or more monitors connected with different resolutions, then it might work only for the main's one top screen edge.

If you provide some more details I'll try to investigate it. Your monitor setup, hammerspoon version, maybe some logs from it, how to reproduce your issue etc.

Thanks for your response.

Some context:

Whenever I press the e key on my keyboard, mission control is triggered. In system settings I've disabled all shortcuts related to mission control but still gets triggered when e is pressed (although it still types correctly and without issue).

There's a possibility that it's a hardware (keyboard) problem thus I'm trying to find a way to disable mission control before resorting to a keyboard replacement.

Additional info:

Ive got Hammerspoon version 1..0.0 installed. Ive no external monitors. I've added the code to init.lua file and saved it. Accessibility access is enabled and have Hammerspoon to start upon login. I've rebooted my Macbook pro. No errors in the logs. When I press e on my keyboard mission control still gets triggered.

Thanks for trying to help.

@raxigan
Copy link
Author

raxigan commented Sep 4, 2024

This script disables mission control only when dragging a window to the top screen's edge. At the time of writing, macos didn't allow to disable this feature.

In terms of keyboard shortcuts you should be able to disable it somewhere in the system preferences. "e" as a shortcut for mission control is quite strange though and I doubt it's the default one.

@homecb
Copy link

homecb commented Sep 4, 2024

Thanks for the additional info. Looks like I'll have to replace the keyboard.

@yrnehli
Copy link

yrnehli commented Sep 17, 2024

This script now interferes with macOS Sequoia's window tiling system, meaning it prevents windows from filling the screen when dragging to the top edge.

I have made a workaround for this by adding a new event listener on left mouse up:

function fill()
    hs.application.frontmostApplication():selectMenuItem({"Window", "Fill"})
end

function fillOnTopScreenDragging(e)
    if e:location().y == 0.0 then
        fill()
    end
end

hookLeftMouseUp = hs.eventtap.new({hs.eventtap.event.types.leftMouseUp}, fillOnTopScreenDragging)

hookLeftMouseUp:start()

@raxigan
Copy link
Author

raxigan commented Sep 18, 2024

Thanks for your update @yrnehli. Do you know if the original issue with window dragging and mission control activation is still there? I stopped using hammerspoon completely a while ago and the problem seems to be gone (at least for me). Not sure if it got fixed in some os update or I changed sth in my settings in the meanwhile. My last investigation of this issue was more than 2 years ago.

@yrnehli
Copy link

yrnehli commented Sep 18, 2024

@raxigan Yeah, the original issue is still present - you have to drag quite quickly and violently to the top of the screen but it still triggers mission control. It annoyingly interferes with the new native macOS tiling system...

The only other tool I've seen where you can disable this is BetterSnapTool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment