This question asks how to open an HTML file in the default browser on Mac OS.
There is a useful answer which refers to this infamous bit of Perl:
VERSIONER_PERL_PREFER_32_BIT=true perl -MMac::InternetConfig -le 'print +(GetICHelper "http")[1]'
Here's some working Python code:
import shlex, subprocess
env = {'VERSIONER_PERL_PREFER_32_BIT': 'true'}
raw = """perl -MMac::InternetConfig -le 'print +(GetICHelper "http")[1]'"""
process = subprocess.Popen(shlex.split(raw), env=env, stdout=subprocess.PIPE)
out, err = process.communicate()
default_browser = out.strip()
Is there a more direct way?