Disable/Change Firefox Safe Mode Hotkey (Shift)

痴心易碎 提交于 2019-11-29 11:13:55

I've also met with this problem and didn't find a solution. It seems that it is still an open issue: Mozilla Forums thread, Bug 653410, Bug 644175 and so on. As a workaround you can install firefox 3.6 as this feature was implemented since firefox 4, but probably this will not suite you.

Mozilla finally added an environment variable to control this behavior. Unfortunately, configuring this environment variable in a way that applies to the overall graphical system, rather than merely a bash session, is a bit difficult. This used to be done via /etc/launchd.conf, but macOS dropped support for this in v10.10. Fortunately, systemctl offers a .plist file system which can define run programs and define system-wide environment variables at boot, so I published this working .plist file, with instructions for installing and removing it:

https://github.com/mcandre/dotfiles/blob/master/setenv.MOZ_DISABLE_SAFE_MODE_KEY.plist

This is awesome for me, because I like to launch my web browser from anywhere in the GUI with Control+Alt+G via QuickSilver, which of course includes the Alt modifier that Firefox tends to interpret as signaling safe mode.

Until Bug 653410 is fixed, the best workaround I can come up with is to detect when safe mode is launched and handle it in the best way fit for your particular purposes. This may mean killing the Firefox process and launching again, or it may mean warning the user, or both.

When Firefox is launched into safe mode, it writes "LastVersion=Safe Mode" to its compatibility.ini file in its profile directory. An example C# function to watch for this is given below.

    FileSystemWatcher safeModeWatcher;

    private void watchSafeMode()
    {
        string profiles = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mozilla", "Firefox", "Profiles");
        string defaultProfile = Directory.GetDirectories(profiles, "*default*")[0];
        safeModeWatcher = new FileSystemWatcher(defaultProfile, "compatibility.ini");
        safeModeWatcher.NotifyFilter = NotifyFilters.LastWrite;
        safeModeWatcher.Changed += delegate(object s, FileSystemEventArgs e)
        {
            if (File.ReadAllText(e.FullPath).Contains("LastVersion=Safe Mode"))
            {
                // safe mode!
                System.Diagnostics.Trace.WriteLine("safe mode detected!");
                // TODO kill Firefox and launch again, or whatever makes sense for you
            }
        };
        safeModeWatcher.EnableRaisingEvents = true;
        // ...
        // TODO Dispose safeModeWatcher when done
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!