AppleScript可以确定默认的邮件应用程序吗?

时间:2016-05-16 21:35:37

标签: applescript

我想知道是否有办法使用AppleScript来确定当前的默认电子邮件应用是什么。理想情况下,它会返回程序的路径,例如/Applications/Mail.app/Applications/Outlook.app

1 个答案:

答案 0 :(得分:1)

您可以从启动服务首选项文件中识别默认电子邮件客户端。

在El Capitan中,该文件位于~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist。在10.11之前的系统版本中,文件可能直接位于“首选项”文件夹中。

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