从电子邮件附加的文件响应“保存”命令,但不响应“打开”命令。然后,您必须首先保存附件,然后将它们移动到下一个应用程序(在您的情况下添加到“联系人”中)。
附件是消息的“邮件附件”列表的成员:请记住,可能会附加许多文件。
此外,只有“已下载”属性为 true 时,您才能保存附件。
最后但并非最不重要的一点是,似乎在 Snow Leopard 中运行良好的“保存”指令在 El Capitain 中的运行效果并不相同:要保存的文件必须在“保存”之前存在......这就是为什么我添加了“touch”命令来首先创建它(只需在 tempFiles 文件夹中创建条目)。
我还在脚本底部添加了打开的 vCard,并使用 Enter 键在联系人中进行验证。您可能需要延迟一段时间,让计算机处理该卡。
如果按键损坏在您的情况下不起作用,请检查“系统偏好设置”辅助功能设置,以允许您的计算机让脚本控制您的 Mac。
我添加了尽可能多的评论以使其清楚......可能太多了!
set Dest to ((path to desktop folder) as string)
tell application "Finder" to make new folder in Dest with properties {name:"TempFiles"} -- create TempFiles folder
Set Dest to Dest & "TempFiles:"
tell application "Mail"
activate -- not sure is mandatory, but I prefer to see selected mails !!
set ListMessage to selection -- get all selected messages
repeat with aMessage in ListMessage -- loop through each message selected
set AList to every mail attachment of aMessage -- get all attachements
repeat with aFile in AList -- for each attachement
if (downloaded of aFile) then
set Filepath to Dest & (name of aFile)
do shell script "touch " & (quoted form of (POSIX path of Filepath)) -- required because "Save" only works with existing file !
save aFile in (Filepath as alias) as native format
end if
end repeat -- next file
end repeat -- next message
end tell
tell application "Finder" to set CardList to every file of folder Dest whose name extension is {"vcf"}
tell application "Contacts"
activate
repeat with aCard in CardList
open aCard
tell application "System Events" to keystroke return
end repeat
end tell
-- tell application "Finder" to delete folder Dest
如您所见,我仅使用扩展名为“vcd”的文件来过滤临时文件夹的内容...以防万一您选择的电子邮件还包含“联系人”无法处理的其他类型的文件。
在脚本末尾,我删除了临时文件夹。但是,在您测试它之前,我将最后一行仅设置为注释(更安全!)