Chrome Homepage

hadleigh_lynn
New Contributor

Hi,
Just wondering how people have found the best way to get the Chrome Homepage through Casper. Our company is pretty new to Casper, we have only had it in for a few months. I'm pretty windows based myself.
I did try using Composer, opening Chrome, setting the homepage etc. I found this worked however it override pretty much every personal setting the user had in Chrome so I wasnt really happy with that.
How have people done here?
Thanks in advance.

1 ACCEPTED SOLUTION

bentoms
Release Candidate Programs Tester

We use MCX, to manage Chromes homepage.

The key is: com.google.Chrome HomepageLocation

View solution in original post

23 REPLIES 23

bentoms
Release Candidate Programs Tester

We use MCX, to manage Chromes homepage.

The key is: com.google.Chrome HomepageLocation

rmanly
Contributor III

If you only want it set initially but then changeable you can do this.

Google Chrome Management

Master Preferences File

  • loaded on first run of Chrome if no preference file exists in “~/Library/Application Support/Google”
  • installed at “/Library/Google/Google Chrome Master Preferences” or “C:Program FilesGoogleChromeApplicationmaster_preferences”
  • VERY picky about syntax
  • only set as Defaults, user can change later
  • https://support.google.com/chrome/a/answer/187948?hl=en - Default User Preferences
  • http://www.chromium.org/administrators/policy-list-3 Policy List includes all manageable settings
  • “Can Be Recommended: Yes” can be set in master

GBS Student Master Preferences file

{
  "homepage" : "http://www.glenbrook225.org/south/Pages/default.aspx",
  "homepage_is_newtabpage" : false,
  "browser" : {
    "show_home_button" : true,
    "check_default_browser" : false
  },
  "bookmark_bar" : {
    "show_on_all_tabs" : false
  },
  "distribution" : {
    "show_welcome_page" : false,
    "skip_first_run_ui" : true,
    "import_history" : false,
    "import_bookmarks" : false,
    "import_home_page" : false,
    "import_search_engine" : false
  },
  "sync_promo" : {
    "user_skipped" : true
  },
  "first_run_tabs" : [
    "http://www.glenbrook225.org/south/Pages/default.aspx"
  ]
}

EDIT:

Typo. Removed erroneous period from file

scrull
New Contributor

@bentoms I'm running v9.24 and I'd like to set the Chrome homepage to http://www.uncc.edu via MCX for all user profiles in a lab environment.

We already use the jamf setHomePage command for Safari and Firefox which has been working with success. I'm fairly new to managing MCX preferences and some guidance would be appreciated. I basically need to know what to punch in for the MCX fields. This is what I have at the moment, but it doesn't seem to be working:

external image link

gregneagle
Valued Contributor

Domain is com.google.Chrome
Key is HomepageLocation

(Don't know if this actually works, but just translating BenTom's note...)

scrull
New Contributor

It does create the .plist file under /Library/Managed Preferences/<useraccount> now. However, it still isn't setting the home page for Chrome when it launches. Any ideas?

timlarsen
Contributor

I have a dumb question (or maybe two) since I can't get this to work properly. I'm attempting to implement the light touch technique employed by @rmanly, FYI. Does the Master Preferences file have to be inside of a subdirectory named "Master Preference File", or is that just the required text file name. Also what extension does the file need to be? Thanks all for your help!

rmanly
Contributor III

@timlarsen][/url

“/Library/Google/Google Chrome Master Preferences”

Is the full path. Spaces on the file and no extension. It should be noted that some of the settings in here have been broken for a while.

https://code.google.com/p/chromium/issues/detail?id=224410
https://code.google.com/p/chromium/issues/detail?id=263803

For example if you want to suppress first run UI what you really need to do is create an empty file here:

empty file called "First Run" in ~/Library/Application Support/Google/Chrome/

EDIT:

P.S. mind the first bullet point above. If that preference file exists then master Prefs is ignored.

timlarsen
Contributor

Thanks for clarifying @rmanly! I don't know if you or anyone else here has had the same issues that I do... but it honestly appears as if nothing I set within the file is working. I've tested by consistently wiping the contents of ~/Library/Application Support/Google/Chrome (except for leaving my blank "First Run" file) and also trying a few example Master Preferences files from the chromium.org forums (to rule out any syntax issues). In any event I am intrigued by this post which combines the master preferences file with a sort-of default Chrome user profile for deployment (unless one already exists): http://www.thesadmin.com/2014/08/deploying-google-chrome-for-os-x/.

karthikeyan_mac
Valued Contributor

There was a change in homepage in our environment.

We changed the newhomepage in Chrome, Safari and Firefox using the below script. This script works if you know your existing homepage setting in the browser.

#! /bin/bash


#This will reset the Home Page for for all browsers.
# Existing Users

for i in $(/bin/ls /Users | sed -e '/Shared/d' -e '/Deleted Users/d' -e '/.localized/d' -e '/.DS_Store/d' -e '/Adobe/d' -e '/Library/d');
do
defaults write /Users/$i/Library/Preferences/com.apple.Safari.plist HomePage http://newhomepage.xxxxxxx.edu/Pages/default.aspx
chown $i:staff /Users/$i/Library/Preferences/com.apple.Safari.plist
ffold=(oldhomepage)
ffnew=(newhomepage)
sed -i .bak 's/'$ffold'/'$ffnew'/g' /Users/$i/Library/Application Support/Firefox/Profiles/lsbasfxf.default/prefs.js
chown $i:staff /Users/$i/Library/Application Support/Firefox/Profiles/lsbasfxf.default/prefs.js
old=(oldhomepage)
new=(newhomepage.xxxxxxx.edu)
sed -i .bak 's/'$old'/'$new'/g' /Users/$i/Library/Application Support/Google/Chrome/Default/Preferences
chown $i:staff /Users/$i/Library/Application Support/Google/Chrome/Default/Preferences
done

Thanks & Regards,
Karthikeyan

jagress
New Contributor III

Here's what I use to set the homepage in Chrome - whether or not it's already been set. I throw this code into a loop that goes through all of the home folders. Then at the end I move a clean copy into the User Template. It's all part of a larger homepages script that takes care of it for all of our major browsers.

### Chrome ###

    # Define some variables
    chromePrefs="/Users/$user/Library/Application Support/Google/Chrome/Default/Preferences"
    sessionLines=$(awk '/session/ {print NR}' "$chromePrefs" | tail -1)
    urlLineNum=$(awk '{print NR,$0}' "$chromePrefs" | grep -A 10 "$sessionLines" | awk '/"startup_urls"/ {print $1}' | awk 'NR==1')
    urlNewLine='"startup_urls": [ '"${homepage}"' ]'

    # Set homepage if no homepage is set yet
    if [[ $urlLineNum == "" ]]; then
            sed -i '' '/restore_on_startup/d' "$chromePrefs"
            sed -i '' '/startup_urls_migration_time/d' "$chromePrefs"
            sed -i '' "${sessionLines}"'a
                    "restore_on_startup": 4,
                    "startup_urls": [ "HOMEPAGE_REPLACE" ]
                    ' "$chromePrefs"
            sed -i '' "s#HOMEPAGE_REPLACE#$homepage#g" "$chromePrefs"
        echo "No Chrome homepage already set. Set new Chrome homepage to $homepage for $user."

    # Set homepage if there's already one set
    else
            sed -i '' "${urlLineNum}s#.*#${urlNewLine}#g" "$chromePrefs"
                sed -i '' '/startup_urls_migration_time/d' "$chromePrefs"
        echo "A Chrome homepage already set. Set new Chrome homepage to $homepage for $user."
    fi

DBrowning
Valued Contributor II

@jagress can you send a full script for this? I have added your section above for Chrome but whenever I run the script is replacing the entire Preference file with just the startup_urls line of code.

jagress
New Contributor III

Hey @ddcdennisb - Here's the full script...

#!/bin/sh

# SetHomepages.sh

# This script assumes that default preference files for all three browsers have been installed
# with FUT/FEU options in Casper.

# Define homepage based on location
macname=$(scutil --get ComputerName)

if [[ "$4" != "" ]]; then
homepage="$4" # This lets us override homepage setting via Casper Remote or policy
elif [[ $macname == naming_convention_1* ]]; then
homepage='http://this.homepage.com'
elif [[ $macname == naming_convention_2* ]]; then
homepage='http://another.homepage.com'
else
homepage='http://default.homepage.com' # Default if nothing else is specified
fi

# Define admin user for later use
adminUser="macadmin"

# Loop through each user to set homepage prefs
for user in $(ls /Users | grep -v Shared | grep -v npsparcc | grep -v ".localized"); do

    ### Firefox ###

    # Define Firefox Profile directory to reference
    firefoxProfilesDir="/Users/$user/Library/Application Support/Firefox/Profiles"

    # Since there may be multiple profile dirs, loop through each
    for firefoxProfile in $(ls "$firefoxProfilesDir"); do

    # If there's already a homepage set, remove it
    if [[ $(grep -cw 'user_pref("browser.startup.homepage",' "$firefoxProfilesDir"/"$firefoxProfile"/prefs.js) -eq 1 ]]; then
    sed -i '' '/"browser.startup.homepage",/d' "$firefoxProfilesDir"/"$firefoxProfile"/prefs.js
    echo "Deleted old Firefox homepage for $user."
    fi

    # Add the new homepage
    echo "user_pref("browser.startup.homepage", "$homepage");" >> "$firefoxProfilesDir"/"$firefoxProfile"/prefs.js
    echo "Set new Firefox homepage to $homepage for $user."

    done


### Safari ###

    # Use defaults command to set Safari homepage
    su - "$user" -c "defaults write com.apple.Safari HomePage $homepage"
    su - "$user" -c "defaults write com.apple.Safari NewWindowBehavior -int 0"
    su - "$user" -c "defaults write com.apple.Safari NewTabBehavior -int 0"
    su - "$user" -c "defaults write com.apple.Safari LastSafariVersionWithWelcomePage $(cat /Applications/Safari.app/Contents/Info.plist | grep -A 1 CFBundleShortVersion | awk -F '>|<' 'NR==2 {print $3}')"
    echo "Set new Safari homepage to $homepage for $user."


### Chrome ###

    # Define some variables
    chromePrefs="/Users/$user/Library/Application Support/Google/Chrome/Default/Preferences"
    sessionLines=$(awk '/session/ {print NR}' "$chromePrefs" | tail -1)
    urlLineNum=$(awk '{print NR,$0}' "$chromePrefs" | grep -A 10 "$sessionLines" | awk '/"startup_urls"/ {print $1}' | awk 'NR==1')
    urlNewLine='"startup_urls": [ '"${homepage}"' ]'

    # Set homepage if no homepage is set yet
    if [[ $urlLineNum == "" ]]; then
    sed -i '' '/restore_on_startup/d' "$chromePrefs"
    sed -i '' '/startup_urls_migration_time/d' "$chromePrefs"
    sed -i '' "${sessionLines}"'a
    "restore_on_startup": 4,
    "startup_urls": [ "HOMEPAGE_REPLACE" ]
    ' "$chromePrefs"
    sed -i '' "s#HOMEPAGE_REPLACE#$homepage#g" "$chromePrefs"
    echo "No Chrome homepage already set. Set new Chrome homepage to $homepage for $user."

    # Set homepage if there's already one set
    else
    sed -i '' "${urlLineNum}s#.*#${urlNewLine}#g" "$chromePrefs"
    sed -i '' '/startup_urls_migration_time/d' "$chromePrefs"
    echo "A Chrome homepage already set. Set new Chrome homepage to $homepage for $user."
    fi

done

# Set homepages in user template for future users

# Safari
cp "/Users/$adminUser/Library/Preferences/com.apple.Safari.plist" "/System/Library/User Template/English.lproj/Library/Preferences/com.apple.Safari.plist"

# Chrome
cp "/Users/$adminUser/Library/Application Support/Google/Chrome/Default/Preferences" "/System/Library/User Template/English.lproj/Library/Application Support/Google/Chrome/Default/Preferences"

# Firefox (must use these nested loops in case of multiple profiles present)
for profileDir1 in $(ls "/Users/$adminUser/Library/Application Support/Firefox/Profiles"); do
    for profileDir2 in $(ls "/System/Library/User Template/English.lproj/Library/Application Support/Firefox/Profiles"); do
    cp "/Users/$adminUser/Library/Application Support/Firefox/Profiles/$profileDir1/prefs.js" "/System/Library/User Template/English.lproj/Library/Application Support/Firefox/Profiles/$profileDir2/prefs.js"
    done
done

Hi Hi 👋 !

Firstly, loving the layout of the script and it's management of the trio (Chrome, Firefox & Safari) all in one go!

I've seen you posted this in 2015, and was wondering if this still working, if any changes have been made since and if you'd be willing to share an up-to-date version of this script!

 

Keep doing what you're doing, I love it ! :)

 

Kind Regards

DBrowning
Valued Contributor II

@jagress Even when running your exact script, Safari and Firefox are fine. But when I launch Chrome I get the following error: "Your preferences can not be read. Some Features may be unavailable and changes to the preferences won't be saved."

Did you ever see this when testing?

jagress
New Contributor III

@ddcdennisb It's been in production and working for a while, but at one point Google did change things around and I had to modify it. What version of Chrome are you using? Is that the version the preference files were created with? I'll try it out.

DBrowning
Valued Contributor II

@jagress we are currently installing 43.x

DBrowning
Valued Contributor II

@jagress Also this is a new process for my company. they have created a new Intranet site that they want pushed to everyone so this is the first time we are trying to push such configs.

gajones
New Contributor II

@jagress thanks for posting this script. Are you using it with Yosemite machines? I'm finding that only Firefox works.

jagress
New Contributor III

@ddcdennisb Looks like there was a change in the prefs file from 42 to 43. It works for me on 42, but not on 43. I'll have to modify the script to work again. I'll post an updated version when I have it.

McAwesome
Valued Contributor

I just set something like this up today. They key fields to note are gonna be HomepageLocation, RestoreOnStartupURLs, and the various settings you want to be forced(more of them found here) The plus side is that this will set the settings. The downside is it locks the settings. If you have things you want to force, this will work well.

(just copy/paste it into XCode and save it was something like ChromeForcedSettings.mobileconfig)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PayloadIdentifier</key>
    <string>com.managedsettings.profile.chrome</string>
    <key>PayloadRemovalDisallowed</key>
    <true/>
    <key>PayloadScope</key>
    <string>System</string>
    <key>PayloadType</key>
    <string>Configuration</string>
    <key>PayloadUUID</key>
    <string>2015-04-20-6-20</string>
    <key>PayloadOrganization</key>
    <string>Your Org Here</string>
    <key>PayloadVersion</key>
    <integer>1</integer>
    <key>PayloadDisplayName</key>
    <string>Google Chrome Policy</string>
    <key>PayloadContent</key>
    <array>
        <dict>
            <key>PayloadType</key>
            <string>com.apple.ManagedClient.preferences</string>
            <key>PayloadVersion</key>
            <integer>1</integer>
            <key>PayloadIdentifier</key>
            <string>com.normandale</string>
            <key>PayloadUUID</key>
            <string>121-qasd</string>
            <key>PayloadEnabled</key>
            <true/>
            <key>PayloadDisplayName</key>
            <string>Custom: (com.google.Chrome)</string>
            <key>PayloadContent</key>
            <dict>
                <key>com.google.Chrome</key>
                <dict>
                    <key>Forced</key>
                    <array>
                        <dict>
                            <key>mcx_preference_settings</key>
                            <dict>
                                <key>AutoFillEnabled</key>
                                <false/>
                                <key>DefaultBrowserSettingEnabled</key>
                                <false/>
                                <key>BookmarkBarEnabled</key>
                                <true/>
                                <key>HideWebStorePromo</key>
                                <true/>
                                <key>HomepageIsNewTabPage</key>
                                <false/>
                                <key>HomepageLocation</key>
                                <string>www.apple.com/string>
                                <key>PasswordManagerEnabled</key>
                                <false/>
                                <key>RestoreOnStartup</key>
                                <integer>4</integer>
                                <key>RestoreOnStartupURLs</key>
                                <array>
                                    <string>www.cnn.com</string>
                                    <string>www.google.com</string>
                                    <string>www.bing.com/</string>
                                    <string>www.apple.com</string>
                                </array>
                                <key>ShowHomeButton</key>
                                <true/>
                                <key>SyncDisabled</key>
                                <false/>
                                <key>DefaultNotificationsSetting</key>
                                <integer>2</integer>
                                <key>ImportAutofillFormData</key>
                                <false/>
                                <key>ImportBookmarks</key>
                                <false/>
                                <key>ImportHistory</key>
                                <false/>
                                <key>ImportHomepage</key>
                                <false/>
                                <key>ImportSearchEngine</key>
                                <false/>
                                <key>ImportSavedPasswords</key>
                                <false/>
                            </dict>
                        </dict>
                    </array>
                </dict>
            </dict>
        </dict>
    </array>
</dict>
</plist>

mpermann
Valued Contributor II

Does anyone know if it's possible to get rid of the annoying "Welcome to Google Chrome" screen where it asks if you want to set Google Chrome as your default browser the first time you launch Chrome? I've tried @rmanly's master preference file but that window is not suppressed. I know the file is working as other preferences from the file are being loaded on the first launch. I don't want Google Chrome to be set as the default browser and I don't want to see the window below at first launch.b13152fce6b6431788786464370aafc3

Aziz
Valued Contributor

@mpermann

I'm having issues with this as well, but I haven't looked into well enough. I know Google Chrome is ignoring the default browser key in my config profile.

<key>DefaultBrowserSettingEnabled</key>
                                <false/>

From

https://www.chromium.org/administrators/policy-list-3

greatkemo
Contributor II

I know this is an old post, but maybe just maybe someone like me is stuck with Yosemite, and comes across this.

Run the following lines in a login script to set the browser as default for each user.

Assuming Chrome is already installed:

open -a "Google Chrome" --args --make-default-browser
sleep 1
sqlite3 /Library/Application Support/com.apple.TCC/TCC.db "REPLACE INTO access VALUES('kTCCServiceAccessibility','com.apple.loginwindow',0,1,1,NULL);" 
osascript -e 'tell application "System Events" to tell process "CoreServicesUIAgent" to tell window 1 to click button 1' >/dev/null 2>&1
sqlite3 /Library/Application Support/com.apple.TCC/TCC.db "delete from access where client='com.apple.loginwindow';"

Very subtle solution and works quite nicely.

Kamal