This is an example for how to create a pkg which installs a com.apple.launchservices.secure.plist file in the user template, so that certain default apps are preset for new users.
This will not affect the settings of existing users!
macOS 26.4 will prompt the user for changing any file/content type handler dynamically.
On macOS, the LaunchServices process manages (among other things) default apps to open url schemes and file/content types. Directly manipulating LaunchServices' configuration files while a user is logged in and the service is running will not work reliably.
To change the default app settings on an existing user, I recommend utiluti, though the system may prompt for user confirmation on certain kinds of changes.
This package installs a LaunchServices plist file in the User Template folder which is copied to a user's new home directory folder upon creation. Since this file will be in place before the LaunchServices process starts, it should be read by the LaunchServices process without issue.
Edit the com.apple.launchservices.secure.plist file to your needs.
You can compare to the same file at ~/Library/Preferences/LaunchServices/com.apple.launchservices.secure.plist on a system you have set up correctly for reference. You can also use utiluti to determine which apps can handle which url schemes and file/content types and the proper uniform type identifier for a file type.
In the buildLSTemplatePkg.sh script, adapt the values of the variables in lines 12-24 to your requirements. Then build the pkg using by running the buildLSTemplatePkg.sh script.
Upload the installer package file to your device management service and ensure it gets installed before a user is created and logs in for the first time.
When a new user is created and logs in, verify that the file is present in ~/Library/Preferences/LaunchServices/com.apple.launchservices.secure.plist and that the defaults are set correctly.
When you set the default app for the http url scheme using the NSWorkspace API or a tool that uses that API, such as utiluti or the mechanisms provided by many browsers, the default app for https and the public.html file type will be set automatically with the http default app. When using this method to preset the default browser, you have to provide entries for the http and https url schemes as well as the public.html file/content type.
Based on a suggestion and blog post from Christopher Smith.