MacOS – How to change the global stylesheet of Safari from the command line on OS X

defaultsmacossafari

I am looking for a command line solution to change Safari default stylesheet.

This can be configured manually by going to Safari > Preferences > Advanced > Style sheets.

Still, I need this in order to be able to reconfigure a system or deploy the settings.

Best Answer

I've set a stylesheet in Safari and these are the changes that occurred in Safari's plist:

UserStyleSheetEnabled = 1;
UserStyleSheetLocationURLString = "~/Desktop/dsa.css";
WebKitUserStyleSheetEnabledPreferenceKey = 1;
WebKitUserStyleSheetLocationPreferenceKey = "~/Desktop/dsa.css";

Your command line would be:

defaults write com.apple.safari UserStyleSheetEnabled 1 && defaults write com.apple.safari UserStyleSheetLocationURLString "/path/to/css" && defaults write com.apple.safari WebKitUserStyleSheetEnabledPreferenceKey 1 && defaults write com.apple.safari WebKitUserStyleSheetLocationPreferenceKey "/path/to/css"