Anyone have a script for this?
Your script looks good and it's changing the plist as designed. I rewrote it to scan for the most recently used email app and set that to the default. Problem is that launchServices doesn't appear to be reading this plist. It does save data there if I change via Apple's Mail preferences. I've done the lsregister -kill -r command to rebuild launchservices database, but it still won't read in the new setting - even after multiple reboots and threats of reformatting. If you come up with a way for the Mac to actually read this setting, I'd love to hear it.
I spoke with an Apple Engineer who told me settings need to be done via LaunchServices API - a plist edit won't do it, although you can see them in com.apple.launchservices.secure.plist.
So I wrote a program to make those API calls. https://github.com/tmhoule/LaunchSetter It's version 0.1 . Seems to work well despite plenty to do to make it easier to use. Feedback welcomed. Especially positive feedback.
@thoule Did you use this on 10.12 ? I am getting some errors while trying to run the "get https" or any other function.
Thanks!
Yes - I'm running it on 10.12. Haven't seen any issues. please post errors to the github issues tracker and I'll take a look.
Also, here's a python script to set outlook as the default mailto handler. Run it as the user with a LaunchA - don't run as a JSS script or you'll set the default email program for user 'root'.
#!/usr/bin/python
##Import Launch Services framework
from LaunchServices import *
##Set default application for "mailto://" scheme
LSSetDefaultHandlerForURLScheme("mailto", "com.microsoft.Outlook")
@thoule would using sudo
with the -u
option to specify the username not work, to launch the Python script in the correct context?
Also, is that the only command needed to make Outlook 2016 the default, or are some other calls such as LSSetDefaultRoleHandlerForContentType needed as well?
@DanJ_LRSFC I was able to get this working:
#!/bin/bash
userName=$(stat -f %Su /dev/console)
py_script="
##Import Launch Services framework
from LaunchServices import *
##Set default application for "mailto://" scheme
LSSetDefaultHandlerForURLScheme("mailto", "com.microsoft.Outlook")
"
sudo -u $userName -H python -c "$py_script"
Also, I manually changed the default mail client in the Mail.app preferences from Mail to Outlook, and when I did a compare of the com.apple.launchservices.secure.plist file before and after, only the mailto had changed.
HTH,
Adam
@thoule & @scheb - This is my script, building off yours. This will also set Outlook to handle emails, contacts and calendar files.
#!/bin/bash
userName=$(stat -f %Su /dev/console)
py_script="
from LaunchServices import LSSetDefaultRoleHandlerForContentType
from LaunchServices import LSSetDefaultHandlerForURLScheme
LSSetDefaultHandlerForURLScheme('mailto', 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('com.apple.mail.email', 0x00000002, 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('public.vcard', 0x00000002, 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('com.apple.ical.ics', 0x00000002, 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('com.microsoft.outlook16.icalendar', 0x00000002, 'com.microsoft.Outlook')
"
echo "Configuring mail settings for "$userName
sudo -u $userName -H python -c "$py_script"
I also came across these tools that includes one to set Outlook as the default. Testing it out, it seems to only configure mailto, so I'm sticking with my more complete script.
The mailto works great but still having a heck of a time trying to figure out how to make outlook the default cal opener. The script above does not work for cal. :(
@ClassicII .. This should help you out with that... It works for the calendar as well..
Also, here's a python script to set outlook as the default mailto handler. Run it as the user with a LaunchA - don't run as a JSS script or you'll set the default email program for user 'root'.
original code:
#!/usr/bin/python
##Import Launch Services framework
from LaunchServices import *
##Set default application for "mailto://" scheme
LSSetDefaultHandlerForURLScheme("mailto", "com.microsoft.Outlook")
You can get around this with out having to run auser from launchctl
I think I do not have outlook to test though. You could try this:
modified code:
#!/usr/bin/python
from LaunchServices import *
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
from Foundation import NSHomeDirectoryForUser
currentuser, uid, gid = SCDynamicStoreCopyConsoleUser(None, None, None)
home_folder = NSHomeDirectoryForUser(currentuser)
domain = str('%s' + '/Library/Preferences/com.microsoft.Outlook') % (home_folder)
LSSetDefaultHandlerForURLScheme("mailto", domain)
Someone will have to test this though as I have no idea if this works, I don't use Outlook.
Based on the above i seem to have something thats working.
This can be run through the JSS as a policy, and will run as the correct user although it should only run on the login trigger to ensure that the policy does not run on the login screen without a user actually logged in.
#!/bin/sh
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
echo "Running for user ${loggedInUser}"
# Some installs of OS X seem to be missing PyObjC but others done.
# Will try and install to ensure the rest of the script does not fail.
easy_install -pip
su ${loggedInUser} -c 'pip install pyobjc --user --quiet'
# Apples recommended method for working out the currently logged in user.
# Using Python to call the ObjC system call that will return the actual user even if run as root.
# https://developer.apple.com/library/content/qa/qa1133/_index.html
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
# Define the contents of a python script here that sets Outlook
# as the default client to Send as E-Mail in other apps, as well
# as open .ics calendar files and .vcard contact files.
py_script="
import os
import sys
from LaunchServices import *
##Set default application for 'mailto://' scheme
LSSetDefaultHandlerForURLScheme('mailto', 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('com.apple.mail.email', 0x00000002, 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('public.vcard', 0x00000002, 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('com.apple.ical.ics', 0x00000002, 'com.microsoft.Outlook')
LSSetDefaultRoleHandlerForContentType('com.microsoft.outlook16.icalendar', 0x00000002, 'com.microsoft.Outlook')
"
# Run the above python as the currently logged in console user.
sudo -u ${loggedInUser} -H python -c "$py_script"
I tried this with macOS 10.12.6 and Outlook 15.41 .... no luck :-(
Microsoft released a few utilities to help with Outlook, one is to set Outlook as a default mail app.
Mac Outlook Support Utilities
https://blogs.technet.microsoft.com/office_for_mac_support_team_blog/2017/08/10/mac-outlook-support-utilities/
You could package, deploy the app, and provide instructions to users on how to use them. They are a bit odd for apps; not signed and don't provide feedback when it's completed the task.
I second this utility from Microsoft. It works; it's just not great in terms of experience.
[@jhalvorson](@jhalvorson) Yes this will work, but this is not very user friendly. A script, which is running silently in the background would be a better user experience. Does anyone know how this utility from Microsoft works?
There must be a way to change the default mail client to the latest Outlook version in Sierra/High Sierra without installing any 3rd party tools ('duti') or bother users to open Self Service and run this Microsoft tool.
I noticed macadmins now has a pkg file to run Direct Link MailToOutlook
"Simple PKG installer that sets the default e-mail app to Outlook instead of the built-in Mail app (JAMF compatible)"
I haven't tested it. I have been doing the Self Service Option to date.
I have test a lot of these scripts and none seem to work on 10.13.3
I can confirm that @john_bio python script works on 10.13.3. I've linked it to the installation of office and making it available as a support object in Self Service for established users.
@phillyphoto The script worked like a charm for changing the mail client. Not sure why it wasn't changing the default calendar to outlook.
Thanks
Sunil
@john_bio what does the 0x00000002
stand for in the line:
LSSetDefaultRoleHandlerForContentType('public.vcard', 0x00000002, 'com.microsoft.Outlook')
what does the 0x00000002 stand for in the line:
LSSetDefaultRoleHandlerForContentType('public.vcard', 0x00000002, 'com.microsoft.Outlook')
@levans I didn't create the script, but looking at the documentation for LSSetDefaultRoleHandlerForContentType, the 2nd argument is the "LSRolesMask" and 2 should equate to "editor" which means Outlook can read, present, manipulate, and save the item.
Legend, yeah I found the same information, but its great to be able to confirm it.
Many thanks for the quick reply.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.