OSX: Set the user's default browser

Source: Internet
Author: User

Recently, we have encountered a situation where we need to set the user's default browser to Google Chrome, while the system's default browser is safari.

This setting is based on user management of system launch services. This means that, even if you modify the global parameters of the system, the user configuration will be followed if you have specific settings.

As long as the user configuration is designed, it will be relatively troublesome. To change the configuration, it involves a variety of user situations, such as the network user folder, and the user's configuration information is on the server, so the configuration needs to be modified on the server; if the user folder is saved locally, there are two countermeasures: 1. The default user folder template needs to be changed by the system, and the user folder template needs to be traversed and changed; 2: deploy a user-level launchagent service. Every time a user logs in, a program is run to complete the settings. Therefore, mobile users, especially those who do not know when to connect to the company's network, may not know, you need a terminal to deploy a management system, such as jamf or free munki.

The above measures can basically solve the situation of almost all workstations and user configuration, the key is how to solve:

Google Chrome seems simple, because chrome supports an internal command:

open -a "Google Chrome" --args --make-default-browser

However, it will be ineffective for other browsers and other methods are required.

One is to use the following Python script:

#/usr/bin/env python# ------------------------------------------------------# Set default web browser app# # org from: https://gist.github.com/miketaylr/5969656## enhenced version 1.1 by Tony Liu# ------------------------------------------------------from LaunchServices import LSSetDefaultHandlerForURLSchemefrom LaunchServices import LSSetDefaultRoleHandlerForContentTypeimport syswebApp=sys.argv[1]# 0x00000002 = kLSRolesViewer# see https://developer.apple.com/library/mac/#documentation/Carbon/Reference/LaunchServicesReference/Reference/reference.html#//apple_ref/c/tdef/LSRolesMaskLSSetDefaultRoleHandlerForContentType("public.html", 0x00000002, webApp)LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002, webApp)LSSetDefaultRoleHandlerForContentType("public.url", 0x00000002, webApp)LSSetDefaultHandlerForURLScheme("http", webApp)LSSetDefaultHandlerForURLScheme("https", webApp)

For example, if Safari is set as the default

python /path/to/setDefaultBrowser.py com.apple.Safari
Similarly, Google Chrome is

python /path/to/setDefaultBrowser.py com.google.chrome

Another way is to use the open-source tool dutil. It is easy to download and compile, and then run the command:
duti com.google.chrome.canary public.html allduti com.google.chrome.canary public.xhtml allduti com.google.chrome.canary public.url allduti com.google.chrome.canary httpduti com.google.chrome.canary https

Another person made a separate app called defabrowser browser.

Reference technical documents: Launch Services

OSX: Set the user's default browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.