|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")|
And then to read it back:
>>> from LaunchServices import LSCopyDefaultRoleHandlerForContentType >>> LSCopyDefaultRoleHandlerForContentType("public.html", 0x000000002) u'com.operasoftware.operanext' >>> from LaunchServices import LSCopyDefaultHandlerForURLScheme >>> LSCopyDefaultHandlerForURLScheme("http") u'com.operasoftware.operanext' >>>
Could you clarify how to read the values back? I'm not familiar with Python and have some troubles
@miketaylr: About your snippet to get the handler of an extension:
For example: I want to know where the executable of OpenSCAD is. All I know is the file extension. With your snippet I would know the name of the handler, but I need to know where the executable is, so I can run a CLI command.
@wolfpat01 You have probably found out this already, but for other people who might be interested in the same thing: this can be achieved by using Hammerspoon with URLDispatcher extension. Not related to a Python script, but might be useful for some people to know. In addition to that, URLs there can be configured in a flexible manner with the help of regular expressions. Please pay attention that once configures you will need to set Hammerspoon as your default browser for using the aforementioned extension properly.