1

I use skhd to manage system-wide keyboard shortcuts, but occasionally one leaks through and gets picked up by FireFox instead.

How can I disable a keyboard shortcut in FF - specifically the Command-{number} to switch tab - so that even if skhd does drop it, or isn't running, I don't get unexpected behaviour from unintentionally triggering a different shortcut?

| |
  • Did my posted solution work for you? If not, can you add a comment to my answer indicating how I can improve it? – gnubeard Mar 30 at 21:52
1

Phew, this was a tough and interesting one! I'll go over how I did this under Windows, then explain how to do it in Linux. This procedure worked for me with Firefox 74.

DISCLAIMER: This could break your Firefox installation, it does not appear to be recommended, and every time you update Firefox, you'll need to repeat this process. So make sure to back up anything you care about from your Firefox installation, especially the omni.ja file.

(If there was any other way, I'd have recommended it, but so far as I can tell, this is the only way to change the main keyset. (This may be a security consideration on the part of Mozilla to prevent malicious extensions from hijacking certain behavior.))

To accomplish this, I first installed the latest 7zip with the Ninite installer. Then, I navigated to the browser subdirectory of the Firefox installation directory, in my case C:\Program Files\Mozilla Firefox\browser. I then used 7zip to unzip omni.ja to another location.

Then, in the newly-unzipped omni directory, I modified the file chrome\browser\content\browser\browser.xhtml. Here's the diff of the changes I made:

--- browser.xhtml.orig  2020-03-27 16:42:54.377242187 +0000
+++ browser.xhtml       2020-03-27 16:43:01.865242187 +0000
@@ -333,7 +333,6 @@

     <key data-l10n-id="nav-reload-shortcut" command="Browser:Reload" modifiers="accel" id="key_reload"/>
     <key data-l10n-id="nav-reload-shortcut" command="Browser:ReloadSkipCache" modifiers="accel,shift" id="key_reload_skip_cache"/>
-    <key id="key_viewSource" data-l10n-id="page-source-shortcut" command="View:PageSource" modifiers="accel"/>
     <key id="key_viewInfo" data-l10n-id="page-info-shortcut" command="View:PageInfo"   modifiers="accel"/>
     <key id="key_find" data-l10n-id="find-shortcut" command="cmd_find" modifiers="accel"/>
     <key id="key_findAgain" data-l10n-id="search-find-again-shortcut" command="cmd_findAgain" modifiers="accel"/>
@@ -380,17 +379,6 @@
     <key id="key_undoCloseTab" command="History:UndoCloseTab" data-l10n-id="tab-new-shortcut" modifiers="accel,shift"/>
     <key id="key_undoCloseWindow" command="History:UndoCloseWindow" data-l10n-id="window-new-shortcut" modifiers="accel,shift"/>

-
-<key id="key_selectTab1" oncommand="gBrowser.selectTabAtIndex(0, event);" key="1" modifiers="accel"/>
-<key id="key_selectTab2" oncommand="gBrowser.selectTabAtIndex(1, event);" key="2" modifiers="accel"/>
-<key id="key_selectTab3" oncommand="gBrowser.selectTabAtIndex(2, event);" key="3" modifiers="accel"/>
-<key id="key_selectTab4" oncommand="gBrowser.selectTabAtIndex(3, event);" key="4" modifiers="accel"/>
-<key id="key_selectTab5" oncommand="gBrowser.selectTabAtIndex(4, event);" key="5" modifiers="accel"/>
-<key id="key_selectTab6" oncommand="gBrowser.selectTabAtIndex(5, event);" key="6" modifiers="accel"/>
-<key id="key_selectTab7" oncommand="gBrowser.selectTabAtIndex(6, event);" key="7" modifiers="accel"/>
-<key id="key_selectTab8" oncommand="gBrowser.selectTabAtIndex(7, event);" key="8" modifiers="accel"/>
-<key id="key_selectLastTab" oncommand="gBrowser.selectTabAtIndex(-1, event);" key="9" modifiers="accel"/>
-
     <key id="key_wrCaptureCmd"
     key="#" modifiers="control"
     command="wrCaptureCmd"/>
@@ -3748,7 +3736,6 @@
               <menu id="webDeveloperMenu" data-l10n-id="menu-tools-web-developer">
                 <menupopup id="menuWebDeveloperPopup">
                   <menuitem id="menu_pageSource"
-                            key="key_viewSource"
                             command="View:PageSource" data-l10n-id="menu-tools-page-source"/>
                 </menupopup>
               </menu>

As you can see, I removed the key entry for key_viewSource, and removed a reference to that key entry in a menuItem entry. I also removed the key_selectTab[1-8] and key_selectLastTab key entries.

Having done this, now it's time to zip it back up. Navigate to the top level of omni, select all its contents, right-click, select 7-zip, and "Add to Archive."

Set the name for the new archive to omni.ja, set the format to zip, and set compression level to Store.

7zip compression options

I made a backup of the existing C:\Program Files\Mozilla Firefox\browser\omni.ja file, then replaced omni.ja with my modified one.

Finally, open a cmd window, and open Firefox with --purgecaches, e.g. C:\Program Files\Mozilla Firefox\firefox.exe --purgecaches.

At this point, Firefox opens up for me, Ctrl-U no longer shows source, and Ctrl-[1-9] no longer select tabs. Success!

For Linux users, instead of 7zip, you can simply:

[gnubeard@mothership: ~]$ mkdir tmp
[gnubeard@mothership: ~]$ cd tmp
[gnubeard@mothership: ~/tmp]$ unzip ../omni.ja

Make the appropriate modifications, then:

[gnubeard@mothership: ~/tmp]$ zip -qr0XD ../omni.ja *

Don't forget to run firefox --purgecaches to reload omni.ja.

The links I'm including at the end of this post mention using zip -qr9XD, but I believe that sets the compression level to maximum, and for this to work, I believe zip compression cannot be enabled (if you're reading this and disagree, please correct me.)

I put this together to specifically address the concerns listed in the question (Ctrl-U, Ctrl-[1-9]) but I think this should work to remove any of the shortcuts in the main keyset, all of which you'll find in browser.xhtml.

(EDIT: In the course of my research I think I got the original question confused with another I found who wanted to disable Ctrl-U. If you don't want to disable that shortcut, just leave out the viewSource deletions I made.)

Links:

http://shallowsky.com/blog/tech/web/modifying-omni.ja.html

This one was written before browser.xul was renamed to browser.xhtml, and the sed command it recommends unfortunately no longer works with browser.xhtml due to the change in format.

http://forums.mozillazine.org/viewtopic.php?f=27&t=3025663

This is how I discovered the --purgecaches option-- took more Googling than I expected.

https://mike.kaply.com/2013/05/06/dont-unpack-and-repack-omni-jar/

Mike Kaply recommended 7 years ago that nobody do this. It could well be possible to accomplish the desired effect by overriding omni.ja's keyset entries somehow instead of modifying it, but if so, I wasn't able to find documentation about it.

https://developer.mozilla.org/en-US/docs/Archive/Mozilla/XUL/Tutorial/Keyboard_Shortcuts

Obsolete documentation about XUL. Interesting to read, but did not directly help me accomplish this.

| |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.