Safari 7.1 - Set Homepage Per User

kadinams
New Contributor

Hi all,

We have a number of communal use Macbook Pros that are managed by Casper. We are trying to set Safari's default homepage to our intranet server, and despite best efforts, Safari continues to set default to http://www.apple.com. Once its changed manually, it holds per user.

This is what we have done so far as a custom settings:

{Homepage=http://intranet.curriculum.local/, AutoFillMiscellaneousForms=false, com.apple.Safari.ContentPageGroupIdentifier.WebKit2StorageBlockingPolicy=0, NewWindowBehavior=0, WebKitJavaScriptCanOpenWindowsAutomatically=true, AutoFillFromAddressBook=false, NewTabBehavior=1, AutoFillPasswords=false, LastDisplayedWelcomePageVersionString=4.0, com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultTextEncodingName=iso-8859-1, com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaScriptCanOpenWindowsAutomatically=true, AutoFillCreditCardData=false, WebKitStorageBlockingPolicy=0, com.apple.Safari.ContentPageGroupIdentifier.WebKit2PlugInSnapshottingEnabled=false, AutoOpenSafeDownloads=false}

The policy does deploy, and most other settings appear to work.

Any suggestions?

Any suggestions?

1 ACCEPTED SOLUTION

bentoms
Release Candidate Programs Tester

@kadinams, maybe the AlwaysRestoreSessionAtLaunch key should be set.

It's been a while since I wrote https://macmule.com/2013/10/27/how-to-set-safari-7-to-open-at-the-homepage/ & it seems to work still.

View solution in original post

10 REPLIES 10

Aaron
Contributor II

Not sure about the rest of the settings, but I used to manage the Safari homepage via MCX, so you could do it though Managed Preferences (there are mixed results with success with MCX in Yosemite. Or, you could manually script it with:

defaults write com.apple.Safari HomePage "http://intranet/"

You could probably do the same with the other settings.

I'm not seeing any options for this in Configuration Profiles. You could create a custom setting in a config profile using much the same as the above.

mm2270
Legendary Contributor III

Or you could use the jamf binary's built in command called "setHomePage". I haven't used it recently, but I assume it still works. At least the command and corresponding help page are both still present in 9.63.

Run jamf -help setHomePage in Terminal for the full details.

davidacland
Honored Contributor II

Just to add to the options, you can also use a standard config profile (desktop picture is restrictions > desktop), or you can use an Applescript one line command in a policy:

osascript -e 'tell application "Finder" to set desktop picture to POSIX file “/path/to/wallpaper.jpg"'

.
When I've used a custom profile I haven't added most of the other keys you've got there. Only the "NewWindowBehavior" and "NewTabBehavior" set to 0 & 1 respectively as you have it.

bentoms
Release Candidate Programs Tester

@kadinams, maybe the AlwaysRestoreSessionAtLaunch key should be set.

It's been a while since I wrote https://macmule.com/2013/10/27/how-to-set-safari-7-to-open-at-the-homepage/ & it seems to work still.

scharman
New Contributor

This is my script, doesnt work when users change it manually to something else though, any idea?

#!/bin/sh
# The script checks the system default user template
# for the presence of the Library/Preferences directory.
#
# If the directory is not found, it is created and then the
# Safari settings are set.

for USER_TEMPLATE in "/System/Library/User Template"/*
do
defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.Safari HomePage "http://www.bing.com"
defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.Safari NewWindowBehavior -integer 0
defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.Safari AlwaysRestoreSessionAtLaunch -bool false
done

# The script checks the existing user folders in /Users
# for the presence of the Library/Preferences directory.
#
# If the directory is not found, it is created and then the
# Safari settings are set.

for USER_HOME in /Users/*
do
USER_UID=basename "${USER_HOME}"
if [ ! "${USER_UID}" = "Shared" ]
then
if [ ! -d "${USER_HOME}"/Library/Preferences ]
then
mkdir -p "${USER_HOME}"/Library/Preferences
chown "${USER_UID}" "${USER_HOME}"/Library
chown "${USER_UID}" "${USER_HOME}"/Library/Preferences
fi
if [ -d "${USER_HOME}"/Library/Preferences ]
then
defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.Safari HomePage "http://www.bing.com"
defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.Safari NewWindowBehavior -integer 0
defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.Safari AlwaysRestoreSessionAtLaunch -bool false
chown "${USER_UID}" "${USER_HOME}"/Library/Preferences/com.apple.Safari.plist
fi
fi
done
fi
exit 0
Any suggestions?

davidacland
Honored Contributor II

Hi @scharman, we have used very similar code in the past. It is designed to only run once so it will set the home page in the user template for any new users and in the homes for any existing users, but it won't stop the user from changing the home page afterwards.

If you want it to stay set you might be better off with a configuration profile instead.

ngidzak
New Contributor

I have found scripts are more reliable then configuration profiles (but that might change with some of the updates that have occurred on Monday.
I have a 1 line script that sets the safari home page for each device as a run once per computer.
It can be changed to an ongoing and use a variable instead of hard codding the startup page. That way you can create multiple policies with the same script and change the default page for each group of users.

This will also force the start page for each user during login.

defaults write /Library/Preferences/com.apple.Safari Homepage "$4"

kadinams
New Contributor

Thank you all so much!

I had to read about Managed Preferences, but today I had success in implementing it. I have removed the custom settings as above, and replaced them with the Managed Preferences to achieve the desired outcome. I did use @bentoms][/url MacMule Guide for the custom tags, as we are still using 10.9 for our SOE.

I really appreciate your time and professionalism :)

WUSLS
New Contributor

Does anyone know a way to set 2 homepages via defaults? I know I can set it up with a default build account, but I would like to make so I just need to run defaults command to update it, should I need to.

davidacland
Honored Contributor II

Hi @WUSLS, the preference key can only hold one value. The defaults write commands mentioned earlier in the thread can be used to set the value but only to one address.