Change Default Mail on Mac without Launching Mail

I clicked on a mailto link at work again.  Happens from time to time.  The Mac popped up Apple’s Mail as though that might help.  I kept meaning to change my default mail application; maybe today was the day?

Anyway, all of the instructions you will find tend to be, well, the same instructions:  open Mail, open Preferences, do some other stuff.  The trouble is that unless you set up a mail account in Mail you cannot open the Preferences.

Outlook used to have a setting for taking default, but that has gone away because Security!

Anyway, I found a solution (here) involving a small amount of Python which worked perfectly.  Nothing to install.  Just copy and paste and you’re good to go.  If you are not using Outlook, you’ll have to look up whatever the bundle identifier would be for your application of choice.  Here’s the code.

/usr/bin/python2.7 <<EOF
import LaunchServices;
result = LaunchServices.LSSetDefaultHandlerForURLScheme(
print("Result: %d (%s)" % (
    "Success" if result == 0 else "Error"))

(The use of EOF should allow you to copy and paste the entire block into a terminal without having to separately paste each line.)

Have fun with that!


Leave a Reply

Your email address will not be published. Required fields are marked *