4

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.

  • This is one of the reasons I don't use Safari. Not being able to set a default page zoom is mind boggling. Older Safari versions didn't even save your page zoom per site, so you had to redo the zoom every time you visited a site again (seems this is finally fixed in Safari 11.0). – wisbucky Oct 17 '17 at 21:13
0

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.

  • If you don't want to change your display resolution and want to stick with the command, you can add killall Safari to the beginning and open -a Safari to the end. That way, it will automatically restart Safari for you! – user248946 Aug 8 '17 at 13:51
  • 1
    I came from a 27" Apple Cinema display with a resolution higher than 1920 x 1080 and was looking for more screen real estate. So reducing to a resolution lower than what I had kind of defeats the purpose. I'll try to use the extra Terminal commands and see how that works out. Since asking this question I also found: apple.stackexchange.com/questions/286306/… and apple.stackexchange.com/questions/52602/…. I'll post whatever I'll end up using. – hepabolu Aug 8 '17 at 20:06
  • 1
    @Fumbles the script works in that it kills and relaunches Safari. I've run it from Keyboard Maestro with a keyboard shortcut trigger. Thanks – hepabolu Aug 8 '17 at 21:01
  • This link: apple.stackexchange.com/questions/52602/… recommends Tinkertool to change the system font size, which would be an equally nice solution. Tinkertool can also changed the pagezoom but also requires a relaunch of Safari. Unfortunately Tinkertool is not scriptable so that brings me back to the script mentioned before. – hepabolu Aug 8 '17 at 21:05
0

From the answers given above and the link I found to Enable Safari Zoom by Script there are several possibilities:

Shell script

# set pagezoom to 125%
killall Safari
defaults write com.apple.Safari DefaultPageZoom "1.25"
open -a Safari

I added this to a Keyboard Maestro macro that is started by a keyboard shortcut trigger (for now).

# revert pagezoom to 100%
killall Safari
defaults write com.apple.Safari DefaultPageZoom 1
open -a Safari

I added this to another Keyboard Maestro macro that is started by a keyboard shortcut trigger (for now).

This works great but the downside is that Safari needs to be restarted.

Apple script

-- set pagezoom to 125%
tell application "System Events"
    tell application process "Safari"
        set frontmost to true
        keystroke "," using command down
        delay 0.5
        tell window 1
            click button "Advanced" of toolbar 1 of it
            click pop up button 3 of group 1 of group 1 of it
            click menu item 6 of menu 1 of pop up button 3 of group 1 of group 1 of it
            keystroke "w" using command down
        end tell
    end tell
  end tell

or revert back to 100%

tell application "System Events"
    tell application process "Safari"
        set frontmost to true
        keystroke "," using command down
        delay 0.5
        tell window 1
            click button "Advanced" of toolbar 1 of it
            click pop up button 3 of group 1 of group 1 of it
            click menu item 4 of menu 1 of pop up button 3 of group 1 of group 1 of it
            keystroke "w" using command down
        end tell
    end tell
end tell

This changes the page without restarting Safari. But from a Keyboard Maestro macro it doesn't work consistently.

Tinkertool

Tinkertool not only offers the ability to set the pagezoom for Safari, but also to set the default system fontsize. Caveat: change only takes effect after relaunching applications and Tinkertool is not scriptable so it requires manual intervention.

Conclusion

For now I'll stick with the Keyboard Maestro macros running the Apple scripts. When my big monitor is connected, the Logitech webcam is also connected so I added an extra trigger to the macros:

USB Device with Name Containing 'Webcam' is Attached to increase the pagezoom and USB Device with Name Containing 'Webcam' is Detached to revert the pagezoom to 100%.

This allows me to automatically switch the pagezoom when connecting or disconnecting the big screen.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .