google-chromegoogle-chrome-extensionuserscriptsstylishuserstyles

Stylish: "Turn all styles off" from command line?


I frequently end up doing ~5 different manual actions when switching between using my laptop in dark environments and light environments, one of which is clicking Turn all styles off in the Stylish extension toolbar button to disable my dark user styles. I'd like to automate this somehow, probably a script bound to a hotkey. Is there a way to have the same effect as clicking Turn all styles off through the command line or some other way to accomplish this goal? I'm using Stylish in Chrome on Ubuntu.


Solution

  • My findings are that there isn't any way to change chrome extension settings from the command line and that the best way to do this is to set a key binding per @wOxxOm's comment and to use xdotool to send the keystrokes to chrome. There are a lot of gotchas in getting this to work. This is the final command I ended up using:

    xdotool search --class 'google-chrome' windowactivate --sync \
            key --window 0 --clearmodifiers 'ctrl+shift+5'
    

    Chrome doesn't accept the keystrokes if it's not active, so use windowactivate --sync first. It seems that Chrome ignores XTEST events so use --window 0 to force xdotool to use XSendEvent instead. Finally, I had to use --clearmodifiers because I have Caps_Lock and Control_L swapped.