要使用AppleScript将邮件附件保存到外部硬盘,可以按照以下步骤进行操作:
首先,需要创建一个新的AppleScript文件。可以通过打开“Script Editor”应用程序并选择“New Document”来创建一个新文件。
在AppleScript文件中,使用以下代码示例来编写脚本:
tell application "Mail"
set theMessages to selection
repeat with theMessage in theMessages
set theAttachments to every attachment of theMessage
repeat with theAttachment in theAttachments
set savePath to (path to desktop folder as text) & (name of theAttachment)
save theAttachment in savePath
end repeat
end repeat
end tell
上述代码会将选中的邮件中的所有附件保存到桌面上。你可以根据需要修改savePath
变量来指定保存附件的路径。
保存脚本文件时,选择一个有意义的名称,并确保文件类型为“Application”。
双击保存的AppleScript应用程序文件,它将自动打开“Mail”应用程序并运行脚本。
在“Mail”应用程序中,选择要保存附件的邮件,并运行刚刚创建的AppleScript应用程序。脚本将自动保存附件到指定的路径。
请注意,如果要保存的附件文件名与已存在的文件重复,新文件将覆盖现有文件。因此,建议在代码中使用适当的逻辑来处理这种情况。