Change Firefox's zoom by script

Each time I change the monitor I have to zoom in or out firefox. Here’s how to set it via script:

Figure 1: Large

Figure 1: Large

Figure 2: Small

Figure 2: Small

Locate the appropriate file

ls /home/*/.mozilla/firefox/*/prefs.js

Locate the appropriate parameter

grep layout.css.devPixelsPerPx /home/*/.mozilla/firefox/*/prefs.js

Large screen: Set the zoom

#!/usr/bin/env bash
factor=2.5
if grep 'layout.css.devPixelsPerPx' /home/*/.mozilla/firefox/*/prefs.js
then
    sed -i -e "s/^user_pref(\"layout.css.devPixelsPerPx.*$/user_pref(\"layout.css.devPixelsPerPx\", \"$factor\");/" /home/*/.mozilla/firefox/*/prefs.js
else
    echo "user_pref(\"layout.css.devPixelsPerPx\", \"$factor\");" >> /home/*/.mozilla/firefox/*/prefs.js
fi

Small screen: Set the zoom

#!/usr/bin/env bash
factor=1.0
if grep 'layout.css.devPixelsPerPx' /home/*/.mozilla/firefox/*/prefs.js
then
    sed -i -e "s/^user_pref(\"layout.css.devPixelsPerPx.*$/user_pref(\"layout.css.devPixelsPerPx\", \"$factor\");/" /home/*/.mozilla/firefox/*/prefs.js
else
    echo "user_pref(\"layout.css.devPixelsPerPx\", \"$factor\");" >> /home/*/.mozilla/firefox/*/prefs.js
fi

Make the scripts executable

sudo chmod --verbose +x ~/src/scripts/FirefoxZoomIn.sh
sudo chmod --verbose +x ~/src/scripts/FirefoxZoomOut.sh
~/src/scripts/FirefoxZoomIn.sh
~/src/scripts/FirefoxZoomOut.sh

Docking/undocking triggers those scripts, which I’m handling with Autorandr.