近期我们遇到的情况是,须要统一设置用户的默认浏览器为Google Chrome。而系统默认的是Safari。

这个设置是系统Launch Services基于用户管理的。

意思就是说,即便是改动了系统全局參数,假设用户有特定设置。那么会依从用户配置。

仅仅要一设计用户配置,那么就会相对麻烦点。要想改变。会涉及多种用户情况,比方:网络用户目录的情况。用户的配置信息都在server上,所以配置须要在server上改动;假设用户目录保存在本地,那么能够有两种对策,1是:系统默认用户目录模板须要改变。并且须要遍历并改变已登录用户的全部;2是:部署一个用户级别的launchagent服务,每当一个用户登陆后,都会执行一个程序来完毕设置。那么对于移动用户。特别是可能不知道什么时候才干连接到公司网络的情况,就须要一个终端部署管理系统,比方JAMF的或者免费得Munki等等。

上面的措施基本上能够解决差点儿全部的工作站的情况和用户配置情况,关键是怎样解决:

假设是Google Chrome,似乎非常easy,由于Chrome支持一个内部命令:

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

只是要是针对其它浏览器就无效了,须要其它方法

一个是使用以下的python脚本:

#/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 LSSetDefaultHandlerForURLScheme
from LaunchServices import LSSetDefaultRoleHandlerForContentType
import sys webApp=sys.argv[1] # 0x00000002 = kLSRolesViewer
# see https://developer.apple.com/library/mac/#documentation/Carbon/Reference/LaunchServicesReference/Reference/reference.html#//apple_ref/c/tdef/LSRolesMask LSSetDefaultRoleHandlerForContentType("public.html", 0x00000002, webApp)
LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002, webApp)
LSSetDefaultRoleHandlerForContentType("public.url", 0x00000002, webApp)
LSSetDefaultHandlerForURLScheme("http", webApp)
LSSetDefaultHandlerForURLScheme("https", webApp)

使用方法比方设置Safari为默认的,那么就是

python /path/to/setDefaultBrowser.py com.apple.Safari

同理。Google Chrome是

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

另外一个方式就是使用开源工具duti

下载编译非常easy,之后执行命令:

duti com.google.chrome.canary public.html all
duti com.google.chrome.canary public.xhtml all
duti com.google.chrome.canary public.url all
duti com.google.chrome.canary http
duti com.google.chrome.canary https

另外另一个人做了一个单独的app, 叫defaultbrowser

參考技术文档:Launch Services

最新文章

  1. [LintCode] Continuous Subarray Sum 连续子数组之和
  2. Integer cache
  3. 观察者(observer)设计模式
  4. 【WPF学习日记】——Window的DataContext绑定ViewModel
  5. html 页面 ajax 方法显示遮罩
  6. 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
  7. KindEditor 修改多图片上传显示限制大小和张数
  8. 自由的Debian
  9. Druid连接池配置(java无框架)
  10. JSON序列化类
  11. java的poi技术读取和导入Excel实例
  12. AET 本征半导体
  13. 在JSON中遇到的一些坑
  14. jQuery基础语法
  15. C#设计模式--装饰器模式
  16. C# CuttingEdge.Conditions 验证帮助类库 文档翻译
  17. js的一道经典题目
  18. Python 多线程 start()和run()方法的区别(三)
  19. 从代码层读懂 Java HashMap 的实现原理
  20. 双系统在Linux下查看win的硬盘(Ubuntu 16.04 挂载Windows的 硬盘)

热门文章

  1. javascript原生360 开机小动画
  2. oracle中用rownum分页并排序的查询SQL语句
  3. [SDOI2016][bzoj4514] 数字配对 [费用流]
  4. POJ2749 Building roads 【2-sat】
  5. 【HDOJ5555】Immortality of Frog(状压DP)
  6. 关于C++的字符串操作
  7. URL重写IIS7(URL Rewrite Module) 比之前的urlrewrite更方便使用
  8. 又看了一次EM 算法,还有高斯混合模型,最大似然估计
  9. C# Stopwatch详解
  10. python笔记6:模块