Posted on 09-23-2016 09:05 AM
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.
Posted on 09-23-2016 09:15 AM
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.
Posted on 09-23-2016 10:10 AM
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.
Posted on 09-23-2016 10:30 AM
@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.
Posted on 09-23-2016 11:00 AM
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".
Posted on 09-23-2016 03:27 PM
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
Posted on 09-23-2016 07:22 PM
Info on Chrome master preferences/setting defaults here:
Posted on 09-23-2016 11:50 PM
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.
Posted on 09-24-2016 08:52 AM
@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.
Posted on 09-24-2016 09:23 AM
@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.
Posted on 09-26-2016 08:51 AM
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"
Posted on 10-31-2016 12:15 PM
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?
Posted on 03-31-2017 02:02 PM
Does anyone know if this works ? It does not work for me.
Posted on 04-01-2017 01:20 PM
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
Posted on 12-18-2018 06:01 AM
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.
Posted on 01-28-2020 08:33 PM
Check out my post here.