Need login help?

Log In   

Shell Script Can Fix Safari 6 Default Fonts

Safari 6.0, which Apple released into the wild at the same time it did Mountain Lion, lacks the preference option for setting the default proportional font and fixed-width fonts. Fortunately, you can still set them using other methods, as described in the TidBITS article "Fix Your Fonts in Safari 6," 14 August 2012. One of those methods involves issuing a series of shell commands in Terminal.

If you use TextExpander, though, you don't have to launch Terminal. Instead, you can create a shell script snippet that can issue the necessary commands, including commands to quit and restart Safari so that the changes take effect. As a bonus, the fill-in capabilities of a script can be used so you can specify the fonts and sizes you want when you expand the snippet, as seen in the following shell script snippet (developed by Michael and Norman Cohen):

#!/bin/bash
if [[ $(ps -ax | grep -i safari | grep -v grep | wc -l) -ge 1 ]] ; then osascript -e "tell application \"Safari\" to quit";  fi
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2StandardFontFamily ’%filltext:name=font-face:default=Lucida Grande%'
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFontSize %filltext:name=default-font-size:default=14%
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2FixedFontFamily ’%filltext:name=fixed-font-face:default=Consolas%'
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFixedFontSize %filltext:name=fixed-font-size:default=11%
osascript -e "tell application \"Safari\" to activate"

To use it, create a shell script snippet containing the above text, assign an abbreviation to it, and then type the snippet abbreviation in any text environment; Safari's location/search bar works just fine. A fill-in window appears with the commands ready to execute, and with fields present in which you can enter different fonts and sizes. Enter the fonts and sizes you want, click OK, and the shell commands are executed.

—Posted by Michael E. Cohen on August 16, 2012

Read more about Take Control of TextExpander







Permalink