在脚本执行之前,我想知道Mac OS X机器上的默认浏览器是否是Google Chrome。
我该怎么做?谢谢!

最佳答案

您可以grep/awk启动服务首选项列表来确定哪个浏览器设置为默认浏览器:

x=~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist; \
plutil -convert xml1 $x; \
grep 'https' -b3 $x | awk 'NR==2 {split($2, arr, "[><]"); print arr[3]}'; \
plutil -convert binary1 $x

这会将变量(x)设置到启动服务首选项列表,然后使用plutil格式将其转换为xml格式,以便我们可以grep它。我们找到要查找的字符串(https),然后输出结果。最后一步是将plist转换回binary格式。
如果chrome设置为默认值,您将得到:
结果:
com.google.chrome

08-18 02:04
查看更多