在脚本执行之前,我想知道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