Setting Default Browser Immediately

lilylily
New Contributor II

I’m trying to push a default browser as an initial setting for the first time that a user logs into their machine. I’ve currently got a package working that installs a preconfigured com.apple.launchservices.secure.plist to each user’s ~/Library/Preferences/com.apple.LaunchServices directory. Right now that package works properly to set the default browser once each user has logged out and then logged back in but I haven’t been able to figure out which service I need to reload in order to get this to work as soon as the .plist is first installed.

 

Ideally the sequence of events would be:

1) User logs in for the first time

2) My preconfigured .plist is installed

3) A postinstall script loads the newly installed .plist and sets the default browser immediately

 

I pulled the command :

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user

from this script https://github.com/aysiu/Mac-Scripts-and-Profiles/blob/main/ChromeDefaultBrowser.sh but it doesn't seem to have any effect on my test machine. Has anybody done this before or have any pointers for doing so?

8 REPLIES 8

mm2270
Legendary Contributor III

Hey there. Nowadays, dropping a pre-configured plist into a directory isn't going to work to load those settings in, as you've already discovered. There's a few reasons for this, but one is due to aggressive preferences caching by the OS. It's been this way for a number of years now, so it's not something new.

One tactic that used to work to get those settings to load was to do a killall cfprefsd (Core Foundation Preferences Daemon) after the plist is in place. I don't know if that still works under Big Sur and/or Monterey as I haven't had a need to do that in a while. But you can try. I also don't recall now if the killall command needs to be run as the logged in user or if running it as root is sufficient.

lilylily
New Contributor II

Ah, thanks for this. It doesn't seem like killing cfprefsd works on Big Sur or Monterey. Is there any other good way to set a temporary default web browser right now or is this just another one of those things that Apple really doesn't want us to be able to do anymore?

mm2270
Legendary Contributor III

I wish I could say, but I don't know. It probably is yet another one of those things Apple doesn't want us to be able to control. The list seems to get longer each year, doesn't it?

I was going to suggest trying to use PlistBuddy to manipulate the plist, but then I remembered that PlistBuddy is not cfprefs cache aware either, so you'd run into the same issue it seems. Anyway, that's a complicated plist to edit even when using PlistBuddy.

In looking at your order of operations, can you rearrange things a little? Right now you listed...

1) User logs in for the first time

2) My preconfigured .plist is installed

3) A postinstall script loads the newly installed .plist and sets the default browser immediately

How about...

1) My preconfigured .plist is installed into /Users/<username>/Library/Preferences/com.apple.LaunchServices/

2) User logs in for the first time

3) There is no step 3!

You are using Jamf Pro after all, so having a package install into a user's directory before they log in and setting them as the owner of that plist should be possible under the right circumstances.

lilylily
New Contributor II

Ah, I was considering going this route at first too but since we're using Jamf Connect to create our user accounts on the fly the user home directories don't exist until they're logged into, hence the workflow I had initially come up with. Thank you for all your suggestions though!

mm2270
Legendary Contributor III

Ah, got it, I didn't know Jamf Connect was in play here. Hmm, in that case that's a bit tricky. Can't really drop something into the user account until it exists.

I'm not really sure I have any other good suggestions. If I think of anything else you can try, I'll drop another reply here.

BTW, you don't have to mark my replies as the answer if they really aren't the answer for you. Just saying.

lilylily
New Contributor II

Lol, I'm not sure why that's happening actually. I haven't marked anything as the answer myself, it seems to be happening automatically.

LukeMason
New Contributor III

I don't know if anyone has made any progress on this, but I'm running into the same problem.

I'm using this script: https://github.com/palantir/jamf-pro-scripts/blob/main/scripts/Set%20Default%20Browser%20and%20Email...

but it requires a reboot.

We also have the Guest account in our environment, and the script doesn't work at all for the Guest account.

As a stopgap solution, I have setup a "Files & Processes" policy (ongoing on login) which runs the following command

/usr/bin/open -a "Google Chrome" --args --make-default-browser

 This pops up a dialog box on login so the user can choose between Chrome and Safari

I'm still holding out hope that there is some way to set this silently...

DDP
New Contributor

Hi @LukeMason,

Curious if you were able to find a way to set Chrome silently and avoid that dialog box?

Thank you.