我正在努力在AppleScript中构建一个小插件,该插件将找到默认的邮件应用程序并将其打开并粘贴到主题和正文中。
我收到错误“预期的行尾但找到了标识符。”
on run
set mailClient to getDefaultMailClient() -- store application id
tell application id mailClient
set msg to make new outgoing message with properties {subject:"subject here", visible:true}
tell msg to make new to recipient with properties {address:"email.com"}
end tell
end run
on getDefaultMailClient()
set prefPath to (path to preferences as text) & "com.apple.LaunchServices.plist"
tell application "System Events"
try
value of property list item "LSHandlerRoleAll" of ¬
(first property list item of property list item "LSHandlers" of ¬
property list file prefPath whose value of property list items ¬
contains "mailto")
on error
"com.apple.mail"
end try
end tell
end getDefaultMailClient
这在我的计算机上打开程序邮件时工作正常但我希望它适用于Entourage和OSX的任何其他电子邮件程序。
非常感谢任何帮助。
答案 0 :(得分:0)
您可以通过为每个客户端编写命令来执行此操作。
if mailClient = "com.apple.mail" then
tell application "Mail"
--insert your code
end tell
else if mailClient = "com.something.else" then
tell application "something.else"
--insert your code
end tell
end if
答案 1 :(得分:0)
您可以利用mailto:
URL方案提供的抽象优势 - 而不是预测各种客户端并为其创建特定代码 - 它将在默认电子邮件客户端中打开一个新的电子邮件表单:
on newEmailForm(addr, subj, body)
do shell script "open " & ¬
quoted form of ("mailto:" & addr & "?subject=" & subj & "&body=" & body)
end newEmailForm
# Sample invocation:
my newEmailForm("somebody@some.net", "This is my subject line", "")
请注意,上述内容使用do shell script
而非open
而不是open location
- 前者可以方便地自动对字符串进行编码以包含在URI中,而后者则要求您通过编码的字符串。