avoid menubar to show

456 views
Skip to first unread message

marco...@gmail.com

unread,
Apr 22, 2021, 12:07:23 PM4/22/21
to Hammerspoon
Hi,

I like to keep the menubar hidden so I enabled this option in macos. However,  sometimes I move my mouse pointer to the top of the screen and then the menubar shows up.

I'm wondering if there is a way to use hammerspoon to keep menubar always hidden even if I pass the mouse pointer to the top of the screen. I workaround I was considering is to create a thread to keep checking mouser position and blocks the mouse to move "too much" to the top, so preventing menubar to show accidentally. (not sure about the feasibility or performance on this direction).

Any tips or directions would be very welcome.

Thanks

asmagill

unread,
Apr 22, 2021, 5:30:30 PM4/22/21
to Hammerspoon
The following seems to work for me, though I admit I've minimally tested it:

ev = hs.eventtap.new({hs.eventtap.event.types.mouseMoved}, function(e)

     if e:location().y < 1 then

         return true

     else

         return false

     end

 end):start()


Then ev:stop() to return things to normal.

--
A-Ron

asmagill

unread,
Apr 22, 2021, 5:38:08 PM4/22/21
to Hammerspoon
Thinking about it more, you should probably change the callback function to something like:
... function(e)
    local sf = hs.screen.mainScreen():fullFrame()
    local loc = e:location()
    if loc.y < (sf.y + 1) and loc.y > (sf.y - 1) then
        return true
    else
        return false
    end
end

This should still allow you to move between multiple screens if one is on top of another.

You may find that you need to change the "+ 1" or" - 1" to a larger absolute value (i.e. "+ 2" or "- 2"), not sure what range pops up the menu on the "bottom" screen and I don't have multiple screens available at the moment to test with, but this should get you started.

--
A-Ron

Marco A. S. Netto

unread,
Apr 22, 2021, 9:00:38 PM4/22/21
to asmagill, Hammerspoon
Hi A-Ron,

Thanks a lot, the solution works perfectly. I've put a shortcut to
enable and disable the functionality. Such a relief to see that
menubar going away for good :)

Just for my understanding, is this "return true | false" statement
saying to ignore or not ignore the event of type mouseMoved?
> --
> You received this message because you are subscribed to the Google Groups "Hammerspoon" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hammerspoon...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/d64af370-66e2-4723-8dcc-b2d8617b5d85n%40googlegroups.com.

asmagill

unread,
Apr 22, 2021, 9:07:29 PM4/22/21
to Hammerspoon
Basically yes. Eventtap also allows you to inject your own events as well to replace or in addition to it, but in this case we just want to "eat" the event when the mouse is in that range.


--
A-Ron

Marco A. S. Netto

unread,
Apr 22, 2021, 9:12:00 PM4/22/21
to asmagill, Hammerspoon
Thanks, really appreciate it.

On Thu, Apr 22, 2021 at 10:07 PM 'asmagill' via Hammerspoon
> To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/e2a6cabd-36ed-45e7-9b5a-97facd7ddcd3n%40googlegroups.com.

Nathan Clark

unread,
Jan 11, 2023, 6:58:35 PM1/11/23
to Hammerspoon
Would you guys mind including a timer, where after n seconds it would show the menubar?
Reply all
Reply to author
Forward
0 new messages