Using an AS application as default email application

Dear Friends,
I hope someone else might get some use out of this appeal. I know I’m taking up way too much of you great guys’ time, but I’ll soon have this new OS up to snuff!

In my old OS 9, I used FileMaker Pro with a suite of plugins to be my contact manager, job billing, etc, AND to do my emailing. The databases work well in OS X, and so does the email function. But, I’m missing one thing in the new OS X: my “open location URL” function. I had a small Applescript applet, as follows:

on open location emailURL
set oldDelims to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “mailto:”
set theAddress to item 2 of the text items of emailURL – get everything after the “mailto:”
set AppleScript’s text item delimiters to oldDelims

tell application "Finder"
	activate
	beep 2
end tell

tell application "Internet Explorer"
	Activate
	set theTitle to item 2 of (GetWindowInfo -1)
end tell

tell application "Finder"
	activate
	beep 2
end tell


tell application "FileMaker Pro"
	activate
	try
		open file "Macintosh HD:02  Lucky Pro:02.01  Lucky Productions:02.01.01  Lucky Business:!!! Current:6_2_1_Corr_Email.fp5"
	on error
		choose file
	end try
	do script "New IM from IE"
	set data of cell "out Email Address [IM]" of current record to theAddress as string
	set data of cell "out Subject [IM]" of current record to theTitle as string
end tell

end open location

As you can imagine, I used the old “Internet” Control Panel to define this applet as the Default Email Application. So, when I clicked on a mailto: URL in a Web page, the call to open the mailto: URL got transferred to my emailing databases. (Filemaker itself, even with the plugins I have, does not, as far as I know, recognize the “open URL” or “GetURL” system events. Hence the need for the intermediary applet. But it worked most of the time!) Now I’m tring to do the same thing in OS X. I’ve rewritten the script slightly, to reflect my understanding of what I’ll need in OS X (and to accomodate a few small changes in my FMP database):

on GetURL(email)
set the text item delimiters to “mailto:”
set email_addressing to text item 2 of email
set the text item delimiters to “@”
set email_name to text item 1 of email_addressing
set email_address to text item 2 of email_addressing

tell application "FileMaker Pro"
	activate
	try
		open alias "Macintosh HD:Users:buckyedgett:02  Lucky Pro:02.01  Lucky Productions:02.01.01  Lucky Business:!!! Current:6_2_1_Corr_Email.fp5"
	on error
		choose file
	end try
	do script "New from IE"
	set data of cell "Addressing} Out To Name" of current record to email_name as string
	set data of cell "Addressing} Out To Email" of current record to email_address as string
end tell

end GetURL

However, when I try to Use OS X’s Mail application to choose my new applet as the default email app, Mail refuses to do it! I can Browse to my applet, and choose it, but when I reopen Mail, it has switched my choice to a different script. How Mail has decided which script to choose on its own, I don’t know.

I do notice that even though I have Finder Prefs set to show extensions, my app has none. I am using Save As in my script Editor, and choosing to show extension, but my app ends up having none in the desktop. If I Get Info on my app, it reads as an application, and the Preview column says it’s an application.

An hour and a half on the phone with Apple Tech Support (I’m still in my first ninety days, can’t you tell?) stumped the experts for sure.

So, heaving a huge sigh of frustration, I beg for help and forgiveness here. A few questions:

  1. Is my script going to work? Does it look good to you guys?
  2. Does anyone know why the OS and Mail, refuse to accept my applet as a default email reader?
  3. You might notice that I’ve left out the Explorer tell. Eventually, I would like to add a routine that might recognise more than one “caller,” or initiator, such as Safari and Explorer, so that I can have my Subject info back, and have it for multiple apps. any suggestions?

Thanks a million for being so accomodating.

Look here:
http://bbs.applescript.net/viewtopic.php?t=8675

Dear jj,
Well, no wonder the poor ignorant tech support guy couldn’t answer my question. Do I really have to do all that to make this work? If so, I’m in way over my head. As in WAY WAY over my head. There’s not a chance my Operating System would ever survive my ignorant attempts to hack it that deeply!

The more I work with this OS X, the less I like it. It’s so closed off to the average user. I guess the Microsft “We know best and you’ll take it or be left out” attitude has finally taken over Apple, as well.

Thank you very much for your time in reading my post and finding the thread. I’ll save the thread as a Web archive (I notice the original poster never DID say she had made her project work!) and read over it a few more times. But for now, I remain, like the “expert” I spoke to, stumped. Muchas gracias.

There is an easier way to register a protocol helper than by using the long method involved in the post mentioned above. Although the other method does have it’s merits, especially in the case of distribution apps, for users who only want a solution for themselves the following is much more practical.

This method assumes that you have internet explorer installed. Simply go into IE’s preferences, and select “Protocol Helpers”. Scroll down to the ‘mailto:’ helper, and then use the obvious “Choose…” button to navigate to your app. From there, you’ll have to figure out your app and make sure it can handle being the protocol helper under all circumstances. I personally would find it annoying… given the large number of methods that one could activate a default mail application… if it were only scripted to handle clicks from one browser or application.

BTW, there ARE other more comprehensive applications out there that fill this apparent “gap” in osx’s abilities… including some that aren’t half bad and all of which are not made by M$. There’s the preference pane More Internet, and the freeware app MisFox. Hope these are what your looking for.

j

Well, this is not user-intended knowledge at all, but for programmers. AppleScript is a scripting language, and accessing system resources is not easy, so you must rely on external tools or just hack what you can (as explained in the mentioned thread). It’s the same as if you try to talk directly to a printer. It sounds as cheenese to me, but investigating most probably you can do it, even using AppleScript and a scriptable tool for devices…

Dear Jobu,
Thanks for your helpful suggestion. I should have included a few bits of info in my original post.

  1. I am now running OS 10.3.7. In 10.3.7, the 10.2.x Internet Preferences Pane has been replaced by a .Mac PrPane. The new PrPane is what forced me to use Mail to (attempt to) change the email protocol to my script.
  2. I also tried the switch in IE, but to no avail. IE will not act independently. It picks up whatever I have done in Mail, and refuses to hold any change I make in it.

Please excuse my having omitted mentioning the IE failure.

I can certainly appreciate your cogent comments concerning the corner into which I am painting myself. There ARE, indeed, as I mentioned in my posts above, several things I would like to include in my potential GetURL script. You may note that in my old one, I had a few lines of code that got the window title from IE and sent it to Filemaker for use as the Subject line. Of course, that worked only when I clicked from IE, and I had no way to discriminate a click from a different app. I’m sure this is going to turn out to be beyond me!

However, the use of a GetURL event from a mailto: URL is pretty basic. If I use Apple’s Mail app as my default helper, all it does is create a new message and paste the URL in the Address field. Mail isn’t even smart (or diligent) enough to parse out the “name” from the URL and put it in the new message’s Name field. In my FMP suite, I can at least do that, although many email URLs don’t include a true “name.” I don’t now remember, having used my suite so long, but I don’t think Eudora did anything more, either.

So, if all I’m “usually” going to get from “the large number of methods that one could activate a default mail application” is an email address pasted into a To field, I’m pretty sure my script can handle that, yes, thanks. You’re right, that makingit fancier than that is probably beyond me! :wink:

And, I can’t thank you enough for pointing me to the helpers. The “gap” is a gulf, as far as I’m concerned. But then, I’m old fashioned! Thanks again for taking the time to reply. I’m off to look for software.

Dear Friends,
Well, according to misFox (thank you, thank you, thank you!) my script is chosen as the default email helper. However, its extension does not show in misFox, but then, neither do any other application’s.

And, when I click a mailto: URL in Explorer, the goofy OS tries indeed to open a script, but, never mine! :o It picks a new application script every few times I try a mailto: click. Oh brother! The OS also presents me with a message saying “This is the first time you will have opened this application…” and I have just been cancelling that alert.

Why the OS refuses to use MY script I haven’t a clue. Well, time presses, so I will come back to this later; perhaps next week. In the meantime, thanks for all your patient help. You’ve made what could have been a very frustrating mess fun. Thanks again. You guys are tops.

Why the OS refuses to use MY script I haven’t a clue.

You will need to modify your script app or it’s resources using one of the methods jj described in the thread he referred you to, otherwise the OS won’t recognize the app as ‘unique’, but will (almost always) default to another ‘aplt’ script app.

It’s not that tough a job, and if your app has a resource fork, you can use ResEdit in Classic to make the needed changes.

Believe me, jj knows his stuff on this… and a lot of other stuff as well.

Peter B.


Hi,

Did you try changing your system default email app. You said you changed it in Mail, but I was thinking that you might need to change it in the equivalent of System Preferences (Jaguar).

Disregard if this does not apply here.

gl,

Dear Kel,
Yes, thanks. As outlined–incoherently, I’m sure–above, I’m using Panther (10.3.7) and I got misFox to try doing that. (Panther having continued the M$-style “Use our software or we shoot this dog” trend by replacing the Internet Preference Pane with a dot Mac pain [strikethrough] Pane.) OK, OK, I’m smiling.

Dear Peter,
Thanks for confirming my (less certain all the time) suspicion that I’m not TOTALLY incompetent. Why Applescript cannot create an “applet” the OS will accept as a unique application is best, at the moment, not discussed. I’d like to have SOME hair left after this rigamarole! I will be looking over jj’s instructions later.
You’re probably right that, in the end, this won’t be THAT tough a job. It’s just a bit daunting to me as a complete novice at OS X! I’m looking at other applications and see they have their “plist” files stored in folders with them. I’m hoping saving my script as a bundle will provide a similar result for me.
All right, guys, it’s supposed to be the weekend, and I’m going fun surfing. theonion.com calls! See you next week, and thanks many times over for your gracious and patient support.

Sure! I think this way is easier (no messing with resource fork), and the process is the same. It’s only the method which changes. If you create a “AppleScript Application” in Xcode, you can edit all info through an nifty interface, but you are really editing the “.plist” bundled file (for carbon apps it’s the same, but editing the resource “plst”, but there are still some dependencies from older days -creator types, etc-).

Dear Friends,
It’s a beautiful sunny day, the snow on the lane is melting, and I’m raring to go. Except I’m stuck on square one.

My email_helper.scpt refuses to save any kind of editable “bundle” I can see. I’ve tried all the combinations of Run Only, Stay Open, etc. using both the Script Bundle and Application Bundle choices in the pop up list. My “application” never has an extension, even though I give it one in the Save As dialog box, and the Hide Extension button is unchecked.

I can see extensions for lots of files. (However, I can’t find a .app file that shows me anything other than a Preview. I also can’t seem to find any plist files that show as “parts” of an “app” file.)

I’ve searched here, and find many threads with mentions of bundles, but none that mention not being able to make one! It must be frustrating for you guys to get this kind of “I can’t, I can’t” post, but really, I’m stuck! Any advice greatly appreciated.

Forgive me if I’m stating the obvious here, but you’re probably just missing an easy step somewhere. An app, as far as I know, needs to be named “.app”. Clicking “Save As…” as you’ve done, typing in a name, selecting “application bundle” as the format, and clicking ‘Save’ should take care of it for you. An application has an extension of .app whether you like it or not, checking hide extension only determines whether it shows up in the finder or not. It has no bearing on whether it actually HAS an extension… it does and always will.

An application bundle is really a folder that contains all of the files necessary to create an “application”. In the finder though, you can’t just open up this folder as you would any other. You have to explicitly choose to view the contents of the bundle. While holding down the “control” key, click on your app. This will bring up a contextual menu, one option of which is “show package contents”. Selecting this option will show the “bundle” of the app. It is a folder which contains all of the files and resources which make up the application. In the ‘contents’ folder, is the info.plist folder into which you place your protocol helper property key/value pairs outlined in the post jj mentioned.

j

Dear Jobu,
Please don’t think of apologizing for stating the obvious: NOTHING about this procedure is going to be obvious to ME.

You were right about using the special contextual menu choice. That does it. Perhaps I was mis-remembering how I had seen these special types of files, or was otherwise confused. I’ve just opened my “bundled app’s” info.plist.

(However, I cannot add the .app extension to my bundle. At first I thought Script Editor was balking, but now I find that the Finder is the culprit. The Finder will not allow me to add “.app” to the name, even if I try to type it by hand in a Finder window. I can edit the name text any other way. But if I type “.app” at the end of the name, the “.app” text disappears as soon as I click off the name.)

At any rate, Finder is TREATING my file “email_helper” as a bundle. I used TextEdit to open my info.plist for email_helper and found:

Now, however, on reading the thread referenced above, I see that what jj was doing for cutie was creating a new protocol (that he called “bakunin” [Ah, those wild and crazy Spanish anarchists, huh?] and she called “rapt.” [Short for “raptor”? Some cutie.])

I presume they created the new protocol because cutie wanted to send and receive very specific files via a .cgi she was writing, and wanted to use her new protocol IN THE SAME WAY the “mailto:” is used. But, I want to highjack the “mailto:” whenever any application invokes it, not use a new or different protocol. jj posted the following code to “add” to cutie’s info.plist:

This is pretty cool. I can see that my applet is an applet:
applet
And that it has Type and Creator codes (I’m familiar with them from using FileBuddy in OS 9.2.2):
APPL
aplt
I wonder about:
LSPrefersCarbon

Am I not working in Cocoa in OS 10.3.7? Does this matter?

And finally, can I use jj’s code, adding it to my info.plist I assume just before the " WindowState" line? If I use his code, I assume I’d have to change the word “bakunin” to “mailto” and use MisFox to choose email_helper as the default email protocol helper. Whew. (Does it at least sound like I’m fumbling my way to understanding what’s going on?)

Thanks a heap, guys, for all your patient help. You’re the tops.

I must add a supplement: modify also the “PkgInfo” file, so it does match your creator type.

Feel free to download this sample:

http://homepage.mac.com/julifos/soft/beta/mailto_handler.app.sit

I did the following:
-Open Script Editor and type

on open location foo
     display dialog foo
end

-Save as Application Bundle
-Browse package contents and edit “Info.plist”
-Modify CFBundleSignature (it was “aplt” and it is now “CACA”)
-Add the magical lines in the plist file:

	<key>CFBundleURLTypes</key> 
	<array> 
		<dict> 
			<key>CFBundleURLName</key> 
			<string>mailto handler</string> 
			<key>CFBundleURLSchemes</key> 
			<array> 
				<string>mailto</string> 
			</array> 
		</dict> 
	</array> 

-Modify the “PkgInfo” file (it contains now “APPLCACA”)
-Compress app. Delete original app. Empty trash. Uncompress app (so launch-services recognizes it as a potential “mailto” handler)
-Use Mail to switch the new default email client to the brand new protocol helper in my desktop.

As it is now, you should be able to uncompress the file I linked above (mailto_handler.app) and just use Mail to change the default email handler to it.

I think that if you re-edit and re-save the app in the Script Editor all the files are overwriten, so keep a copy at hand of both the “Info.plist” and “PkgInfo” files, just in case you need’em later.

Good luck! :wink:

Dear Friends,
Sorry to have been so long replying. My browsers have been having a heck of a time getting MacScripter to load!

It works. I think. At least, it works in theory, in that I can get it to work for a while. For some unknown reason, the OS every now and then decides to do what it was doing before we learned the inner secrets of the plist: that is, choose another, random script to open when I invoke an “open location email URL” by clicking a mailto link.

Or, it may be that I did not follow the excruciatingly correct procedure after I edited my script and replaced the bundled application with a new one. I’ve been messing with this so much I can’t now remember the exact circumstances.

It IS true that one must follow an exact set of steps that seem to be:

  1. create a bundled app as stay open;
  2. edit its plist and info files;
  3. Use Mail (no other utility will work) to choose it as the default email application;
  4. Compress it, trash it, decompress the stuffed file;
  5. Log out and log back in.

It might be the case that #s 3 and 4 have to be switched. Or that #5 isn’t really necessary. In ANY case, it’s not easy getting the OS to permanently accept the script as the default email app. I’m still not positive that the OS HAS accepted it permanently. But I am sure that to get it to work at all, ALL the above steps must be performed. At least, on my machine!

Thanks so much for all the time you guys have put into this. You’re the greatest.

Now, if it seems like it’s going to stick, I’ll need further code to help me create the subject line from the page title, eh? Way cool! Thanks again!

Dear Friends,
Yep, it does. Can’t thank you all, and especially jj, enough.

I’d say the crucial step is the compress-delete-decompress. Why, I have no idea, but nothing else forces the OS to finally accept the bundled app script as a legit application.

It may also help that I changed the name of the bundled app the last time I saved it and went through the “installation” routine. I suspect once the OS has rejected a bundled app script as not quite up to its finicky standards, it will reject any others with the same name. Its voodoo, people.

I’ve also upgraded the OS from 10.3.7 to .8, and the email helper survived the change. Can’t thank you enough.