But now with the new OS it always say Apple Mail even if Outlook is the default.
I am no expert in script so I hope you can help me to fix it so it also works in the new OS
try this, its uses the property list suite of System Events rather than the shell.
Maybe the key “mailto” is different, I can’t test it because using default Mail.app the entry is missing
set mailTo to "com.apple.mail"
tell application "System Events"
set plistFile to (POSIX path of file "com.apple.LaunchServices.plist" of preferences folder)
tell contents of property list file plistFile
repeat with anItem in (get property list items of property list item "LSHandlers")
if exists property list item "LSHandlerContentType" of anItem then
if value of property list item "LSHandlerContentType" of anItem is "mailto" then
set mailTo to value of property list item "LSHandlerRoleAll" of anItem
end if
end if
end repeat
end tell
end tell
error “System Events got an error: Can’t get file "com.apple.LaunchServices.plist" of preferences folder.” number -1728 from file “com.apple.LaunchServices.plist” of preferences folder
PS. Some of the plist labels have changed too, so Stefan’s script would have to be:
set mailTo to "com.apple.mail"
tell application "System Events"
set plistFile to (POSIX path of file "com.apple.launchservices.secure.plist" of folder "com.apple.LaunchServices" of preferences folder)
tell contents of property list file plistFile
repeat with anItem in (get property list items of property list item "LSHandlers")
if exists property list item "LSHandlerURLScheme" of anItem then
if value of property list item "LSHandlerURLScheme" of anItem is "mailto" then
set mailTo to value of property list item "LSHandlerRoleAll" of anItem
end if
end if
end repeat
end tell
end tell
return mailTo
On my machine, the new file was created one second before the old one was last modified, on the evening I installed Yosemite. This suggests Mavericks used the old path, but it’s hardly conclusive proof!
I was guessing the label name, because as I never changed the default mail application I don’t have “mailto”.
I’m still on Mavericks, the script using System Events works fine with with the randomly picked “public.html” value.
You could also use this under Mavericks and Yosemite:
use framework "Foundation"
use framework "AppKit"
on pathToEmailApp()
set theNSWorkspace to current application's NSWorkspace's sharedWorkspace()
set theNSURL to theNSWorkspace's URLForApplicationToOpenURL:(current application's NSURL's URLWithString:"mailto:")
return theNSURL's path() as text
end pathToEmailApp
It would have to be in a script library under Mavericks. OTOH, it’s massively faster.