Skip to content

Instantly share code, notes, and snippets.

@sheagcraig
Last active August 7, 2019 14:35
Show Gist options
  • Save sheagcraig/16e9d6a01406de06c524 to your computer and use it in GitHub Desktop.
Save sheagcraig/16e9d6a01406de06c524 to your computer and use it in GitHub Desktop.
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/env python3
# 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.
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
OUTLOOK = "com.microsoft.outlook"
def main():
result = set_mail_reader(OUTLOOK)
human_result = "succeeded" if result == 0 else "failed"
print("Setting Outlook to handle mailto links: {}".format(human_result))
def set_mail_reader(bundle_id):
"""Use LaunchServices to set mailto handler.
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/
"""
return LSSetDefaultHandlerForURLScheme("mailto", bundle_id)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment