Chuck
Chuck

Reputation: 4892

Can AppleScript determine the default mail app?

I'd like to know if there's a way to use AppleScript to determine what the current default email app is. Ideally it would return the path to the program, such as /Applications/Mail.app or /Applications/Outlook.app.

Upvotes: 0

Views: 250

Answers (1)

vadian
vadian

Reputation: 285082

You can identify the default email client from the launch services preference file.

In El Capitan the file is located in ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist. In system versions prior to 10.11 the file might be directly in the Preferences folder.

set bundleIdentifier to missing value
set LSPrefFilePath to (path to preferences folder as text) & "com.apple.LaunchServices:com.apple.launchservices.secure.plist"
tell application "System Events"
    set LSPrefFile to property list file LSPrefFilePath
    tell property list item 1 of contents of LSPrefFile
        repeat with anItem in (get property list items)
            if exists property list item "LSHandlerURLScheme" of anItem then
                if value of property list item "LSHandlerURLScheme" of anItem is "mailto" then
                    set bundleIdentifier to value of property list item "LSHandlerRoleAll" of anItem
                    exit repeat
                end if
            end if
        end repeat
    end tell
end tell
if bundleIdentifier is missing value then
    set defaultMailClient to "/Applications/Mail.app"
else
    tell application "Finder" to set defaultMailClient to POSIX path of (application file id bundleIdentifier as text)
end if

Upvotes: 1

Related Questions