Change current users homepage and startup pages in Safari and Chrome

Taboc741
New Contributor III

So I have been given an edict from my communications people that I will have to update all the macs home pages and start up pages in Safari and Chrome across my org. They have also promised in an email comm to the users that when IT does this the users will be able to set it back if they so want. It's the setting them back part I am having trouble with. I can set the Plist like google recommends, but then they are stuck with my choice. I can change the default values in that plist, but from what I understand that doesn't affect machines that already have a preferences Json. I tried the script that was so kindly published here: https://jamfnation.jamfsoftware.com/discussion.html?id=9868 but it doesn't change the Safari settings and more concerning, it seems to corrupt the current chrome prefs file causing Chrome to revert to default.

I'm a windows junkie who got handed the mac platform a few months ago (after the old mac team retired). I am struggling with Bash having come from a PowerShell world and my google fu apparently sucks because I can't find what to edit in the prefs file to make this work. I got the windows side working, but the same values don't seem to work on mac. Any help or pointers folks?

Lastly my project to get my JSS updated to 9.93 is delayed again so I'm stuck with 9.81 for now.

15 REPLIES 15

duffcalifornia
Contributor

What I might do is create DMG's of both Safari and Google. Use Casper Imaging, take your starting snapshot, install chrome and set the homepage, take your ending snapshot, then create it as a DMG and then ensure fill user template (FUT) and fill existing users (FEU) are checked in Casper Admin. Make sure that you're not signed into anything and you don't do anything else before creating the snapshot. Do the same thing with Safari, except you don't need to install safari - I would do this on a blank test machine to make sure that your browser history isn't pulled into the template. Then push both out via policy on recurring check in.

Taboc741
New Contributor III

The problem is that would over write all the settings users had. Once again the arbitrary powers that be have promised on behalf of IT that nothing else would be changed but the homepage and start up page.

Yes I agree the powers that be should have talked to me first, but something about water under the bridge.

mpermann
Valued Contributor II

@Taboc741 if they don't care if the end user changes the homepage back after you have set it then I don't see the point of you setting it in the first place. Would you be allowed to add it as a Self Service plugin? Then you could just direct everyone to Self Service. Side benefit is you'd get your end users into the Self Service application and get some exposure. Could be helpful especially if you aren't using Self Service much.

Taboc741
New Contributor III

We already have the new homepage set as a plug-in. I think the goal here is to replace the blank google and apple start-up pages with our branded home page so there is a better chance of people seeing our internal news feeds, but they don't want to risk the ire of people who had far more functional start up preferences...like restore my last tabs. So they compromised with the phrase "well you can change it back".

r0blee
New Contributor II

So I'm not sure where the Google Chrome preferences are but it shouldn't be hard to find them but Safari stores it's preferences in ~/Library/Preferences/com.apple.Safari.plist

So what you can do is a defaults write command into that plist to change the value.

Below is my terminal output showing the following:

My first command was my initial defaults read command to check in ~/Library/Preferences/com.apple.Safari.plist what the current value of the key 'HomePage' is set to. In this case, http://apple.com

The 2nd command is me performing a defaults write command into the file ~/Library/Preferences/com.apple.Safari.plist saying that for the Key value 'HomePage' write the value to be 'http://jamfnation.jamfsoftware.com'

My 3rd line was just a repeat of the defaults read to make sure the write command ran correctly.

You should be able to do something similar with the Google Chrome plist.

Hope that helps.

Rob

115a5353ba374f53b7dbb131226968f3

RobertHammen
Valued Contributor II

Info on Chrome master preferences/setting defaults here:

Chrome

bentoms
Esteemed Contributor
Esteemed Contributor

Why not use config profiles for this?

You can set Safari & Chromes homepages both with profiles from the JSS.

These won't mess with user prefs etc.

I can post examples if @taboc741 wants.

mpermann
Valued Contributor II

@bentoms won't a config profile enforce the homepage and prevent the end users from changing it? If not, I'd be interested in an example. Thanks.

bentoms
Esteemed Contributor
Esteemed Contributor

@mpermann oh yep. Missed the requirement from the OP to allow folks to reset.

The same keys should work via a script, but there is some jiggery pokery needed to show the homepage so it's not just one plist key.

Another thing might be a simple AppleScript app you can put in the Dock, this app just opens the URL wanted for a homepage in their preferred browser.

Taboc741
New Contributor III

So it looks like I got it working by modifying the original script I mentioned pretty significantly. I'm posting what I have working below for everyone else's sake.

#!/bin/sh

# SetHomepages.sh
#  Change Chrome and Safari Homepage

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

# Define homepage

homepage='https://www.yourhomepage.com'

# Stop all open browsers so settings are not over written by Coogle Chrome's open session (it re-writes every 1 min from memory)

sudo killall -z -m "Google Chrome"
Sudo killall -z -m "Safari" -signal

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

### 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 - "users" -c "defaults read com.apple.Safari"
echo "Set new Safari homepage to $homepage for $user."


### Chrome ###

# Define Chrome Preference variable
chromePrefs="/Users/$user/Library/Application Support/Google/Chrome/Default/Preferences"

#Parse the Preferences json file to set the homepage
sed -i '' 's|"startup_urls":"[A-F0-9]*"|"startup_urls":""|' $chromePrefs
sed -i '' 's|"startup_urls":[[]"http[^"]*"[]]|"startup_urls":["$homepage"]|' $chromePrefs
sed -i '' 's|"homepage":"http[^"]*"|"homepage":"$homepage"|' $chromePrefs


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"

dannyd
New Contributor

I use this config profile for safari:

[https://www.jamf.com/jamf-nation/discussions/19668/homepage-in-safari-9-on-el-capitan#responseChild124431](link URL)

Can you post sample with Chrome?

imgappleadmin
New Contributor

Does anyone know if this works ? It does not work for me.

gachowski
Valued Contributor II

I think all the easy methods stopped working a while back... I had this working for a while but Apple changed "stuff" and it broke...

https://managingosx.wordpress.com/2015/02/02/command-line-tools-via-python-and-cocoa/

Or a config profile...

C

HJFitservices
New Contributor

We are attempting to preform the same process for all of our supported browsers (Safari, Chrome & Firefox). We initially setup a configuration profile, with plist files to define the home page to our required web site. This we were able to perform for Safari & Chrome, however we have not had the same success with Firefox. Another issue we are running into deals with the problem of the homepage setting now being locked. This is not something we want for our users. Please let me know if you have any additional ideas, as we try to setup a default home page, instead of a locked home page for Safari, Chrome & Firefox.

woodsb
Contributor

Check out my post here.