Skip to content

Instantly share code, notes, and snippets.

@typemytype
Last active January 16, 2017 11:54
Show Gist options
  • Select an option

  • Save typemytype/5fed5b08cb6c51c26747bef458ffdb76 to your computer and use it in GitHub Desktop.

Select an option

Save typemytype/5fed5b08cb6c51c26747bef458ffdb76 to your computer and use it in GitHub Desktop.
set the default app by file extension in python
import LaunchServices
import AppKit
fileExtension = "thisShouldBeACoolFile" # file extension
UTI = LaunchServices.UTTypeCreatePreferredIdentifierForTag(LaunchServices.kUTTagClassFilenameExtension, fileExtension, None)
r = LaunchServices.LSSetDefaultRoleHandlerForContentType(UTI, LaunchServices.kLSRolesAll, AppKit.NSBundle.mainBundle().bundleIdentifier())
if r != 0:
print "oeps"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment