OSX:设置用户默认浏览器
2014-09-29 12:28
344 查看
最近我们遇到的情况是,需要统一设置用户的默认浏览器为Google Chrome,而系统默认的是Safari。
这个设置是系统Launch Services基于用户管理的。意思就是说,即便是修改了系统全局参数,如果用户有特定设置,那么会依从用户配置。
只要一设计用户配置,那么就会相对麻烦点。要想改变,会涉及多种用户情况,比如:网络用户文件夹的情况,用户的配置信息都在服务器上,所以配置需要在服务器上修改;如果用户文件夹保存在本地,那么可以有两种对策,1是:系统默认用户文件夹模板需要改变,而且需要遍历并改变已登录用户的所有;2是:部署一个用户级别的launchagent服务,每当一个用户登陆后,都会运行一个程序来完成设置;那么对于移动用户,特别是可能不知道什么时候才能连接到公司网络的情况,就需要一个终端部署管理系统,比如JAMF的或者免费得Munki等等。
上面的措施基本上可以解决几乎所有的工作站的情况和用户配置情况,关键是如何解决:
如果是Google Chrome,似乎很简单,因为Chrome支持一个内部命令:
不过要是针对其他浏览器就无效了,需要其他方法
一个是使用下面的python脚本:
用法比如设置Safari为默认的,那么就是
另外一个方式就是使用开源工具duti。下载编译很简单,之后运行命令:
另外还有一个人做了一个单独的app, 叫defaultbrowser。
参考技术文档:Launch Services
这个设置是系统Launch Services基于用户管理的。意思就是说,即便是修改了系统全局参数,如果用户有特定设置,那么会依从用户配置。
只要一设计用户配置,那么就会相对麻烦点。要想改变,会涉及多种用户情况,比如:网络用户文件夹的情况,用户的配置信息都在服务器上,所以配置需要在服务器上修改;如果用户文件夹保存在本地,那么可以有两种对策,1是:系统默认用户文件夹模板需要改变,而且需要遍历并改变已登录用户的所有;2是:部署一个用户级别的launchagent服务,每当一个用户登陆后,都会运行一个程序来完成设置;那么对于移动用户,特别是可能不知道什么时候才能连接到公司网络的情况,就需要一个终端部署管理系统,比如JAMF的或者免费得Munki等等。
上面的措施基本上可以解决几乎所有的工作站的情况和用户配置情况,关键是如何解决:
如果是Google Chrome,似乎很简单,因为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。下载编译很简单,之后运行命令:
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
相关文章推荐
- OSX:设置用户默认浏览器
- OSX:设置用户默认浏览器
- 怎样按照个人爱好设置默认浏览器
- 设置LINUX 服务器中FTP 用户登录的默认目录
- Axure RP Pro - 相关问题 - 设置打开原型的默认浏览器
- 设置VS默认浏览器
- 设置或解除ie,firefox,chrome为默认浏览器
- 如何设置默认浏览器
- VS2005和VS2008设置默认浏览器
- KB959753:如何自定义Vista/2008/XP/2003的默认用户设置
- 恢复(设置)IE为默认浏览器
- VS 2005 中如何设置默认浏览器
- 技术QA:如何更改用户配置文件和程序设置的默认位置?
- flex builder3 设置默认浏览器
- 设置默认浏览器L设置默认浏览器L
- C#使用浏览器(Internet Explorer)默认的代理服务器设置(WebRequest,WebClient,HttpWebRequest)
- "彻底地"设置Firefox(Maxthon)为你的默认浏览器
- 登陆页中将用户设为guest默认用户的设置
- windows XP 设置系统登陆默认用户
- flex builder3如何设置默认浏览器