Set pagezoom of Safari programmatically

defaultssafari

I recently bought a 4K monitor and love the screen real estate. But the standard fonts are becoming a bit too small to read. So I plan on writing a script in Keyboard Maestro to change the default PageZoom in Safari to 125% when I press a button.

I have figured out that I can set the pagezoom with this command in the Terminal:

defaults write com.apple.Safari DefaultPageZoom "1.25"

This works because defaults read com.apple.Safari DefaultPageZoom reports the set value back. AND the Safari preferences also show the value set.

But page in Safari doesn't change. However, when I change the PageZoom in the Preferences manually the page DOES change.
I've tried reloading the page and changing the window size after setting the PageZoom in the Terminal, but nothing works.

What do I need to do to make the defaults write setting become active?

I don't want to use the CMD+ and CMD- keys all the time.

In the end I want Keyboard Maestro to trigger this script when I plug in a device that signals I'm using this monitor.

Best Answer

You need to

  1. close Safari
  2. run the Terminal command
  3. re-open Safari

Most (if not all) defaults write commands require you to quit or kill the affected application or process to see the results.


To solve your problem you may think about setting the display resolution from 3840 x 2160 to 1920 x 1080 (Retina / HDPI). This will increase the size of all display elements including text in Safari.

Go to System Preferences > Display and change the resolution there.