Create a gist now

Instantly share code, notes, and snippets.

@sheagcraig /Makefile
Last active Jan 26, 2016

What would you like to do?
Set Microsoft Outlook as Default Handler for mailto, vcf, and ics
# Put in /usr/local/share/luggage/ to reap the rewards.
USE_PKGBUILD=1
l_usr_local_outset: l_usr_local
@sudo mkdir -p ${WORK_D}/usr/local/outset/{firstboot-packages,firstboot-scripts,everyboot-scripts,login-every,login-once,on-demand}
@sudo chown -R root:wheel ${WORK_D}/usr/local/outset
@sudo chmod -R 755 ${WORK_D}/usr/local/outset
pack-outset-firstboot-packages-%: % l_usr_local_outset
@sudo ${INSTALL} -m 755 -g wheel -o root "${<}" ${WORK_D}/usr/local/outset/firstboot-packages
pack-outset-firstboot-scripts-%: % l_usr_local_outset
@sudo ${INSTALL} -m 755 -g wheel -o root "${<}" ${WORK_D}/usr/local/outset/firstboot-scripts
pack-outset-everyboot-scripts-%: % l_usr_local_outset
@sudo ${INSTALL} -m 755 -g wheel -o root "${<}" ${WORK_D}/usr/local/outset/everyboot-scripts
pack-outset-login-every-%: % l_usr_local_outset
@sudo ${INSTALL} -m 755 -g wheel -o root "${<}" ${WORK_D}/usr/local/outset/login-every
pack-outset-login-once-%: % l_usr_local_outset
@sudo ${INSTALL} -m 755 -g wheel -o root "${<}" ${WORK_D}/usr/local/outset/login-once
pack-outset-on-demand-%: % l_usr_local_outset
@sudo ${INSTALL} -m 755 -g wheel -o root "${<}" ${WORK_D}/usr/local/outset/on-demand
include /usr/local/share/luggage/luggage.make
TITLE=set_default_outlook
REVERSE_DOMAIN=com.sas
PAYLOAD=\
pack-outset-login-once-set_outlook_default_handler.py \
PACKAGE_VERSION=1.0.0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_metadata</key>
<dict>
<key>created_by</key>
<string>shcrai</string>
<key>creation_date</key>
<date>2015-12-15T18:33:37Z</date>
<key>munki_version</key>
<string>2.4.0.2561</string>
<key>os_version</key>
<string>10.11.2</string>
</dict>
<key>autoremove</key>
<false/>
<key>catalogs</key>
<array>
<string>production</string>
</array>
<key>category</key>
<string>Config</string>
<key>description</key>
<string>Sets Outlook to handle all mailto, ics, and vc links.</string>
<key>developer</key>
<string>SAS</string>
<key>display_name</key>
<string>set_default_outlook-1.0.0</string>
<key>installed_size</key>
<integer>5</integer>
<key>installer_item_hash</key>
<string>763c5fd3879bbbd643ba29bc0f62bf5f9d861d540ac81fbbd166fb598e33b501</string>
<key>installer_item_location</key>
<string>set_default_outlook-1.0.0.pkg</string>
<key>installer_item_size</key>
<integer>4</integer>
<key>minimum_os_version</key>
<string>10.5.0</string>
<key>name</key>
<string>set_default_outlook</string>
<key>receipts</key>
<array>
<dict>
<key>installed_size</key>
<integer>5</integer>
<key>packageid</key>
<string>com.sas.set_default_outlook</string>
<key>version</key>
<string>1.0.0</string>
</dict>
</array>
<key>requires</key>
<array>
<string>outset</string>
</array>
<key>unattended_install</key>
<true/>
<key>uninstall_method</key>
<string>removepackages</string>
<key>uninstallable</key>
<true/>
<key>version</key>
<string>1.0.0</string>
</dict>
</plist>
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2016 Shea G Craig
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Set Outlook as the Default Handler for mailto, .ics, and .vcf.
There is a bug in OS X that prevents the user from subsequently
setting the mail handler to anything else.
This script is intended to be run as the user to whom the change will
be applied. outset is the tool we use to run this at login time (as a
login-once script).
"""
from LaunchServices import (LSSetDefaultHandlerForURLScheme,
LSSetDefaultRoleHandlerForContentType,
kLSRolesAll)
def main():
outlook = "com.microsoft.outlook"
set_mail_reader_to_mail(outlook)
set_handler_for_extension_with_role("ics", outlook)
set_handler_for_extension_with_role("vcf", outlook)
def set_mail_reader(bundle_id):
"""Use LaunchServices to set mailto handler.
There is a bug in OS X that allows you to set this only once.
Afterwards, if you set it again, it will revert to the previous
setting within about 10 seconds. Until this is fixed, logging out
really quickly seems to work around it.
Args:
bundle_id (String): Bundle Identifier for the app to handle
mail. Caps do not seem to matter.
Returns:
Integer return code (0 is a success) as per
https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/
"""
result = set_mail_reader_to_mail(bundle_id)
if result == 0:
print "Set {} to mailto handler successfully.".format(bundle_id)
else:
print "Setting {} to mailto handler failed."
def set_handler_for_extension_for_all(extension, bundle_id)
"""Use LaunchServices to set mailto handler.
Args:
extension (String): Content type UTI.
bundle_id (String): Bundle Identifier for the app to handle
mail. Caps do not seem to matter.
Returns:
Integer return code (0 is a success) as per
https://developer.apple.com/library/mac/documentation/Carbon/Reference/LaunchServicesReference/
"""
result = LSSetDefaultRoleHandlerForContentType(
extension, kLSRolesALl, bundle_id)
if result == 0:
print "Set {} to {} handler successfully.".format(bundle_id, extension)
else:
print "Setting {} to {} handler failed.".format(bundle_id, extension)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment