Attempting to write simple mailto: protocol handler

Hello everyone.

I’ve been struggling all night to get the following code to work on my OS 10.4.8

on open location myURL
	display dialog myURL
end open location

I save this as an application bundle in script editor. I’ve procured RCDefaultApp to set both my “mailto” protocol handler and my default mail application to the application bundle I save in the script editor.

RCDefaultApp refuses to set this application bundle as either the mail application or the mailto protocol handler.

So I pull out automator and put the same script in a workflow and save that as an application. RCDefaultApp will now set this new application as both the default mail handler and the mailto protocol handler.

However, clicking on a mailto:// link in firefox will not display the url in the dialog as expected.

None of this would be necessary if setting actually worked in firefox. All I want is a perl script to handle my mailto: URLs. Why is this so hard? (I’m just a bit frustrated.)

So some questions for those who are clearly more experienced at this than I am:

  1. Where is the documentation for protocol handling, launch services, etc? Specifically, I’d like to understand exactly how the mailto: URL is sent from firefox through mac os to the designated application. I can’t find clear documentation on this anywhere.

  2. Does anyone have a clue why the above applescript fails to produce the expected result?

  3. Is there some way I can “see” what is going on? I’m a UNIX wizard, and not afraid of digging deep.

Thanks in advance for any information you folks can provide. Have a better day than I’m having (not hard to do).

Browser: Firefox
Operating System: Mac OS X (10.4)

Use this forum’s internal search for terms ‘protocol handler mailto’.

You’ll probably find something of use.

Peter B.

In point of fact, I’d done something like this search with google which led me here.

None of the links I’ve found yet have explained this problem or offered a solution that works, unfortunately.

I’d seen which I can reproduce perfectly. However,
my script application still doesn’t get “recognized” by “the system” as a mailto protocol handler even after
modifying the package signature and adding (with property list editor) the CFBundleURLTypes entry.

RCDefaultApps simply reselects the application every time I try to select my application for the mailto protocol handler.

Is there any chance of someone explaining exactly how all this works? Is there clear documentation anywhere? What’s it named?
Where can I learn more? I want to learn more. :slight_smile: Hacking in the absence of good information can be fun, but not in this instance.

Hi Dreamingness,

Here’s some links for mozilla:


Thanks, however I’ve seen both of these articles. Sadly, setting “” does not work for firefox on the mac. So far as I can tell, the code in firefox for OS X doesn’t do an exec(). Instead, we have the following C++ code:

[code]nsresult nsOSHelperAppService::LoadUriInternal(nsIURI * aURL)
nsCAutoString url;
nsresult rv = NS_ERROR_FAILURE;

if (aURL)
if (!url.IsEmpty())
if (icService)
rv = icService->LaunchURL(url.get());
return rv;
The key is that “LaunchURL” call there, which (I think…if I could find some documentation on this area it would be quite wonderful) goes through the operating system to get the proper service to send the request to. According to my interpretation of this code (which could be wrong) Firefox can never have a protocol handler for an arbitrary application run directly through firefox…you instead have to go through OS X. In some ways this makes sense.

Do you think this is wrong? When a user clicks on a Firefox mailto url, a new outgoing message is opened in the default email browser? Always? Sometimes? Never?

An addendum. This link is referred to in several threads under the search topic “protocol handler mailto” but seems to be non existant:
Has this been moved? Is there a way to access it?


You know why I say this is because creating a “user.js” file made the mailto links open in my default Mail browser.


Heh. I think that “wrong” is a very subjective term when dealing with user preferences and system behaviors. :smiley: There’s too many people on the planet to think otherwise.

I think what you say makes sense in the general case. For most users, this is a Good Thing: opening the default email browser on their Mac when you click a mailto: link.

However, I’m a power user, and my default mail application sits on my FreeBSD box. I’d like the mailto link to invoke a Perl script which knows how to pop up Emacs remotely which will send the mail the way I want it. If I were to think of anything as “wrong” in this moment of time, it would be that it shouldn’t be as hard as it is proving to be to do something like that. At the moment, with no documentation on Launch Services to be ferreted out of google or the man pages, and no clue why two equal Info.plist files produce two different results, my other two options are to 1) recompile Firefox with a custom patch or 2) write lisp code in Aquaemacs because apparently that application is allowed to handle mailto links as well.

Remember that you did ask me what I think. Apologies if I am ruffling any feathers here. :slight_smile:


No it’s ok to get down to semantics. What I was wondering is if you tried the things on the links for Firefox (with the user.js file) and ever got it to launch A default mail application.


I never had to do that on the Mac…firefox has -always- opened the default Mail application.

Hi Dream,

But did you ever add a user.js file and enter what your default maill app is?

What happened? Possible answers: I didn’t try much. It just opened with my default app and not my preferred app. I could not make anything different happen.


Whenever you see an old macscripter url that references the page with a “t=” in the query string, you can simply change the ‘t’ to an “id” and get the page. Thus,
… should be…

Perhaps the fine administrators have the capacity to add a hook that would catch these old urls and swap an id for a t automagically when necessary? :smiley:


No I never did that. :smiley:

The evidence suggests this will not have an effect, as there isn’t an “exec()” or “system()” call in the firefox source covering that area. Also everything in user.js (prefs.js?) is editable with “about:config”. Finally, to do a real test here, I’d have to put some other app in user.js so as to make sure the system’s application wasn’t being inserted.

Thank you! This worked. Yay for something that works. :wink:

It’s a hack, but if you include the following at the top of the right PHP file:

<?php $_GET["id"] = $_GET["t"]; ?>
the problem would hopefully go away.

Had anybody gotten this to work on 10.4? I too have read all the posts and its just not working…

We use a web portal for email at the office, and I would like a simple app that I could select as my default mail app, and that script would open the login page of our web portal and put the email address of the recipient in the clipboard so a command-v puts it in the rite field in the new email form.

I’ve managed to get this working with the utility “Webmailer” and having it launch a shell script, but it only works in root, other accounts cant select webmailer as default app.

So if any one here actually has an applescript app that can be selected as default mail app and receive the email address, I would like to know how to do this.



I experimented with just this issue on 10.4 and found that I could not make a ‘mailto:’ AppleScript protocol app stick as default in the presence of any other OS X native mail client.

Not no way, not no how… not with .plist changes, not with RCDefault App.

Since I’m still running Classic and much prefer Claris Emailer to Apple’s Mail client, I simply zipped Mail and trashed the original… and use my own AS mailto: protocol… to steer browser clicks to Emailer.

I’m not familiar with Webmailer… but if you’re prepared to disable or trash the other X native mail clients lying around, you may be able to get something else to receive mailto: clicks.

Having said all that, and rereading this thread, I’m not sure I even addressed your question.

So be it.

Peter B.

I’ve come to the same conclusion that is evil incarnate.

If I simply move it to the trash, I can then select my applescript as default mail app with no troubles, then I just move back to the app folder and its reign of terror begins anew.

If anyone finds a solution to this I would appreciate, since I would really hate to have to trash Mail




I may be sending you on a goose chase, but I can’t now recall if my experimentation with Mail’s Info.plist was conclusive… in the end, I didn’t care, and as mentioned, I simply zipped (for safekeeping) and trashed the original.

However, there is an entry in that file that reads like so:


Email Address URL



…and I remember changing ‘DefaultForScheme’ to false… but I’m not sure if I reset/rebuilt the LaunchServices db file (or whatever) afterward… which is probably necessary for the change to work at all.

It might be worth a try, and then again, it might not. A bit Draconian is all, but hey, if it works…

I didn’t try removing the other entries I don’t think, but if you’re desperate, you might try that too.

Be sure to keep an archived copy of Mail - or at least the .plist - handy so you can revert as necessary.

You may also run into trouble with any other OS X native mail client (as mentioned before).

Good Luck.

Peter B.

Yeah I started tinkering with’s info.plist file after all else failed and indeed I got what I wanted.

I tried to set LSIsAppleDefaultForScheme to false, but that had no effect, so I removed the entire CFBundleURLTypes key, and rebuilt launch services with Onyx (as I did after changing LSIsAppleDefaultForScheme), that did the trick. can no longer be selected as default email app. I’m pretty sure if I go into it and configure it it’ll still work as an email app, but it just wont be able to respond to mailto commands.

I use Radmind to deploy my macs so I’ll just do a Radmind loadset that restores the info.plist file for users that would want to use as default client.

Thanks for the help