我是 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命令。富文本、字符、段落、单词、属性运行所包含的元素。properties file (file, r/o) : 附件同步文件名的文件路径
但我不知道如何在 AppleScript 中使用类。再次任何帮助将不胜感激!