Script breaks in Snow Leopard

Someone helped me write this script long ago to get the default email client. It breaks in Snow Leopard. Can anyone help me fix it? Thanks!!!


set creatorType to word -1 of (do shell script ¬
    "defaults read com.apple.LaunchServices |grep -C5 U:mailto | grep -w LSBundleSignature")

set {text:creatorType} to (text of creatorType) as text

I don’t have that key in Launchservices either, and I have never used anything but Apple Mail.
I suspect that key will only be added when you select another email client.

I found similar behaviour elsewhere: keys, and entire plists, will only come into existence when you change some default setting.

Tested hypothesis; opened Mail, and selected FireFox as my email client (yes, I know).
Lo & behold, a ‘mailto’ item pops up in Launchservices’ plist.

Go back into Mail, and reselect Mail as the mail client.
The ‘mailto’ item is still there, but now points to Mail.

Check it for yourself, the key names have changed, too (come to think of it, that alone will break your script).

FWIW, that’s exactly how they are documented to work.

I’ve been looking at this for a few days now trying to figure out how to fix it but with no success…the changes to the Launchservices file has really thrown me. Any help would be greatly appreciated!

Here’s how I solved it.
As I said earlier, this will not work at all when you have never used anything but Mail; the key will be absent.

do shell script "defaults read com.apple.LaunchServices |grep -C5 U:mailto | grep -w LSBundleSignature"
-- fails

do shell script "defaults read com.apple.LaunchServices |grep -C5 U:mailto"
-- fails
-- mmm
-- what's that 'U' good for?
-- (views manpage) ah - "treat as binary"

do shell script "defaults read com.apple.LaunchServices |grep -C5 mailto"
-- works
-- what's that C5 good for?
-- -C5: print 5 lines of output
-- well, that's way too much
do shell script "defaults read com.apple.LaunchServices |grep -C2 mailto"
-- ah, that's better:
-- Result:
-- "                {
--            LSHandlerRoleAll = \"com.apple.mail\";
--            LSHandlerURLScheme = mailto;
--        }
--    );"
-- 
-- but something changed:
-- the mail handler's key is no longer  "LSBundleSignature" but "LSHandlerURLScheme"
-- so:
do shell script "defaults read com.apple.LaunchServices |grep -C2 mailto | grep -w LSHandlerRoleAll"
-- yay!
-- almost there
set shortList to words of result -->{"LSHandlerRoleAll", "=", "com.apple.mail"}
set mailClient to item 3 of shortList --> "com.apple.mail"
set text item delimiters to "."
set mailClientName to text item 3 of mailClient
set text item delimiters to ""
mailClientName--> mail

Install Bwana to read manpages in Safari.

Or perhaps in this form:

try
	set creatorType to word -1 of (do shell script ¬
		"defaults read com.apple.LaunchServices | grep -C1 mailto | grep LSHandlerRoleAll")
on error number 1
	set creatorType to "com.apple.mail"
end try

Thank you both for your help. Works great!

Nigel, your script also works in Leopard, which is a plus.