今天给 gpt 提了一个问题
在 macOS 上的邮件,如何在收到邮件时自动触发并识别信用卡账单,解析 eml 内容,输出成 csv 文件
ta 也给出了正确的思路,关键的一步是“在 Apple Mail 里设置规则,当符合特定条件(如邮件来自银行或标题包含“信用卡账单”)时,触发 AppleScript”,但是就是这一步卡了我好久。
on perform_mail_action(theMailMessages)
tell application "Mail"
repeat with eachMessage in theMailMessages
set senderAddress to sender of eachMessage
set subjectLine to subject of eachMessage
-- 只处理来自银行的信用卡账单邮件
if senderAddress contains "bank@example.com" and subjectLine contains "信用卡账单" then
set emlFilePath to (POSIX path of (path to desktop)) & "bills/" & subjectLine & ".eml"
-- 确保目录存在
do shell script "mkdir -p " & quoted form of (POSIX path of (path to desktop) & "bills")
-- 导出邮件
save eachMessage in file emlFilePath
end if
end repeat
end tell
end perform_mail_action
但是尝试之后,一直看不到导出邮件。继续追问,ChatGPT 提出可能是访问权限的问题?但是我加入了完整磁盘访问权限之后依旧如故。
只好老办法,一点点打断点日志。发现“on perform_mail_action(theMailMessages)”这个代码块根本进不去,告诉 ChatGPT 之后,ta 却反复让我确认,查看日志是否能够正常输出。无法提出正确的解决方案。此时我已经还是怀疑这个语法是否过时了……
最后在 https://stackoverflow.com/questions/59791464/how-to-trigger-applescript-on-apple-mail-rule 找到可行的办法。
using terms from application "Mail"
on perform mail action with messages caughtMessages for rule catchingRule
repeat with caughtMessage in caughtMessages
try
set mailSubject to subject of caughtMessage
display dialog mailSubject
on error errorString number errorNumber
display dialog errorString
end try
end repeat
end perform mail action with messages
end using terms from
总之,ChatGPT 在处理一些代码上确实太粗糙。
#ChatGPT #macOS #AppleScript
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.