I want to find out if the default browser is Google Chrome on a Mac OS X machine before the script executes.
How can I do it? thanks!
The only way is to set it in the main Settings: From the Apple menu, choose System Preferences, then click General. Click the “Default web browser” pop-up menu and choose a web browser, like Chrome.
Hold the Ctrl key, click your user account's name in the left pane, and select “Advanced Options.” Click the “Login Shell” dropdown box and select “/bin/bash” to use Bash as your default shell or “/bin/zsh” to use Zsh as your default shell. Click “OK” to save your changes.
Mac OS X comes with the Bourne Again SHell (bash) as the default user shell and also includes the TENEX C shell (tcsh), the Korn shell (ksh), and the Z shell (zsh). bash, ksh, and zsh are compatible with sh, the original Bourne shell.
Bash is a command-line interface shell program used extensively in Linux and macOS. The name Bash is an acronym for "Bourne Again Shell," developed in 1989 as a successor to the Bourne Shell.
You can grep/awk
the launch services preferences list to find out which browser is set as default:
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
This sets a variable (x
) to the launch services preferences list, then converts it using plutil
to xml
format so we can grep
it. We locate the string we're looking for (https
) then output the result. The final step is to convert the plist back to binary
format.
If chrome is set to be default you will get:
Result:
com.google.chrome
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With