3

Firefox's CMD+Shift+P (on Mac) for new Private Window conflicts the "Move" page keyboard shortcut in Notion.

Looks like there's no way to remap keys within Firefox, OSX Keyboard shortcuts, or even 3rd party Fixefox Adds like Shortkeys. Good & up to date discussion on SuperUser

Exploring hammerspoon as a solution, how would I suppress a key in a certain app?

p.s. There's a good writeup here that discuss rebinding a hotkey with Hammerspoon. This is for reassigning what a hot key will do. I'd like to suppress CMD+Shift+P in Firefox, and rebind CMD+Shift+N to do what CMD+Shift+P did.

snowbound
  • 1,692
  • 2
  • 21
  • 29

1 Answers1

0

I made an example which blocks CMD+F (Find) in Google Chrome and remaps CMD+N (New Window) to this functionality instead.

  • Setup an event tap for the key down event
  • Detect when CMD+F is pressed and return true to block it
  • Detect when CMD+N is pressed and create key events to simulate CMD+F

The trick is to check which is the frontmost (active) application while doing so. Get the bundle ID of the app, and only if its Google Chrome block CMD+F and remap CMD+N. For all other application do nothing to allow the default action.

When CMD+N is pressed a boolean (allowOverride) is set to true to allow the very next CMD+F keypress which is simulated. Not doing this would also block it.

You should be able to rework this example for FireFox and your shortcuts.

local allowOverride = false
local events = hs.eventtap.event.types
keyboardTracker = hs.eventtap.new({ events.keyDown }, function (e)
  local keyCode = e:getKeyCode()
  local flags = e:getFlags()

  if flags.cmd then
    local application = hs.application.frontmostApplication()
    if (application:bundleID() == "com.google.Chrome") then
      if keyCode == hs.keycodes.map.f then
        if not allowOverride then
          return true
        end
        allowOverride = false
      elseif keyCode == hs.keycodes.map.n then
        hs.eventtap.event.newKeyEvent(hs.keycodes.map.cmd, true):post()
        hs.eventtap.event.newKeyEvent("f", true):post()
        hs.eventtap.event.newKeyEvent("f", false):post()
        hs.eventtap.event.newKeyEvent(hs.keycodes.map.cmd, false):post()

        allowOverride = true
        return true
      end
    end
  end
end)
keyboardTracker:start()
Christophe Geers
  • 8,564
  • 3
  • 37
  • 53