Skip to content

Instantly share code, notes, and snippets.

@miketaylr
Last active April 22, 2024 18:01
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miketaylr/5969656 to your computer and use it in GitHub Desktop.
Save miketaylr/5969656 to your computer and use it in GitHub Desktop.
Set default browser on OSX with Python
#/usr/bin/env python
from LaunchServices import LSSetDefaultHandlerForURLScheme
from LaunchServices import LSSetDefaultRoleHandlerForContentType
# 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, "com.operasoftware.operanext")
LSSetDefaultRoleHandlerForContentType("public.xhtml", 0x00000002, "com.operasoftware.operanext")
LSSetDefaultHandlerForURLScheme("http", "com.operasoftware.operanext")
LSSetDefaultHandlerForURLScheme("https", "com.operasoftware.operanext")
@hungLink
Copy link

if you are getting "module not found" run this in your terminal:
pip install pyobjc-framework-LaunchServices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment