【发布时间】:2013-08-05 02:40:17
【问题描述】:
我是 AppleScript 的新手,但通过在线搜索学到了一些东西。基本上我想将 iMessage 消息转发到一个电子邮件地址。我使用以下脚本做到了这一点:
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:"thesubject", content:theMessage, visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"myemail@gmail.com"}
send
end tell
end tell
end message received
end using terms from
效果很好,它会将 iMessage 放入发送给我的电子邮件的内容中。
现在我也在尝试使用附件来执行此操作。我修改了代码,以便在收到文件时发出 4 声哔哔声,但没有任何反应。将此问题发布到Apple的网站,但后来我想我会在这里有更好的运气。任何帮助都将不胜感激,我已经在谷歌上搜索了几个小时,但我有点走投无路了。
修改代码:
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
tell application "Mail"
set theNewMessage to make new outgoing message with properties
{subject:"thesubject", content:theMessage, visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties
{address:"myemail@gmail.com"}
send
end tell
end tell
end message received
on completed file transfer theFile
beep 4
end completed file transfer
end using terms from
所以通过多看几眼,我了解到 Messages 与 iChat 非常相似,我在 Apple 的开发者网站上找到了一些示例代码: https://developer.apple.com/library/mac/#samplecode/iChatAppleScriptSamples/Listings/Add_Incoming_Images_to_iPhoto_Add_incoming_image_to_iPhoto_applescript.html
所以我将代码更改为:
on received file transfer invitation theFileTransfer
accept transfer of theFileTransfer
tell application "Mail"
set theNewMessage to make new outgoing message with properties
{subject:"photo", content:"themessage", visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties
{address:"myemail@gmail.com"}
send
end tell
end tell
end received file transfer invitation
我还确保在消息首选项窗口中传入文件时运行脚本,但仍然没有得到任何响应。非常令人沮丧,我认为图片可能不是文件传输,而是某种内联文本附件。
查看我找到的 Messages 字典:
附件 n [inh.富文本] :表示内嵌文本附件。这个类主要用于make命令。 元素 由富文本、字符、段落、单词、属性运行所包含。 特性 file (file, r/o) : 附件同步文件名的文件路径
但我不知道如何在 AppleScript 中使用类。 再次感谢任何帮助!
【问题讨论】:
-
不幸的是,我现在不在我的 Mac 上,所以在回答这个问题之前,我无法查看 AS 库来做我应该做的研究。看起来您之前的代码中的
theMessage是一个字符串。如果您能找到获取实际消息对象的方法,那么您可以使用get attachment of message_object,我相信库中还有其他方法可以让您在运行该代码之前检查是否有附件。跨度>
标签: email applescript attachment forward imessage