Last active
August 17, 2017 06:43
-
-
Save jlehikoinen/1dbf8c22ce0c88826d363bd3b5274897 to your computer and use it in GitHub Desktop.
Set MS Outlook as default email application in macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
set_outlook_as_default_application.py | |
Description: | |
Set Outlook as a default application for email, calendar and contacts | |
""" | |
import sys | |
from SystemConfiguration import SCDynamicStoreCopyConsoleUser | |
from LaunchServices import LSCopyDefaultRoleHandlerForContentType | |
from LaunchServices import LSSetDefaultRoleHandlerForContentType | |
from LaunchServices import LSCopyDefaultHandlerForURLScheme | |
from LaunchServices import LSSetDefaultHandlerForURLScheme | |
##### EDIT THESE DICTIONARIES ===> | |
UTI_HANDLER_DICT = { | |
'com.apple.mail.email': 'com.microsoft.outlook', | |
'com.microsoft.outlook16.email-message': 'com.microsoft.outlook', | |
'public.vcard': 'com.microsoft.outlook', | |
'com.apple.ical.ics': 'com.microsoft.outlook', | |
'com.microsoft.outlook16.icalendar': 'com.microsoft.outlook' | |
} | |
URL_SCHEME_DICT = {'mailto': 'com.microsoft.outlook'} | |
##### | |
# Obj-C LSRolesMask constant kLSRolesAll hexadecimal representation is 0xFFFFFFFF | |
LS_ROLES_MASK = 0xFFFFFFFF | |
##### | |
def set_handler(): | |
# Iterate dictionary (key: UTI / content type, value: handler / application) | |
for content_type, ls_handler in UTI_HANDLER_DICT.iteritems(): | |
# Change handler | |
print 'Changing default handler: %s for content type: %s' % (ls_handler, content_type) | |
try: | |
LSSetDefaultRoleHandlerForContentType(content_type, LS_ROLES_MASK, ls_handler) | |
except Exception, e: | |
print e | |
sys.exit('Could not change content type handler. Exiting.') | |
def set_scheme(): | |
# Iterate dictionary (key: url scheme, value: handler / application) | |
for scheme, ls_handler in URL_SCHEME_DICT.iteritems(): | |
# Change handler | |
print 'Changing default handler: %s for url scheme: %s' % (ls_handler, scheme) | |
try: | |
LSSetDefaultHandlerForURLScheme(scheme, ls_handler) | |
except Exception, e: | |
print e | |
sys.exit('Could not change content type handler. Exiting.') | |
##### | |
def main(): | |
set_scheme() | |
set_handler() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment