我收到很多客户电子名片到一个特定的电子邮件地址。我想通过邮件规则和 AppleScript 自动将电子名片添加到我的联系人中。
我搜索了很多,发现了一些东西。我稍微修改了一下。并且打开和添加过程工作正常。但只有当我选择一个文件时。我无法从邮件消息中将文件放入变量中。我试过了,但它不起作用。
到目前为止,这是我的代码:
tell application "Mail"
set att to attachment
end tell
set thefile to att
tell application "Contacts"
activate
open thefile
end tell
tell application "System Events" to keystroke return
如果我删除第 1、2 和 3 行并在第 4 行写入“设置文件以选择文件”,那么它将起作用 - 如果我选择一个文件。但是前三行我尝试了一些东西,但没有任何成功。所以我的问题是,如何从消息中获取文件?
谢谢
您真诚的,克里斯
解决方案:
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
delay 1
tell application "System Events" to keystroke return
end repeat
end tell
delay 2
-- tell application "Finder" to delete folder Dest