AppleScript Messages not Working in Mail
I have a simple AppleScript that I am trying to build that will save an email attachment to a file folder on my system. In trying to debug it I am finding the script appears to crash on trying to get any values from the message.
Here is the full script that I want to run:
set attachmentsFolder to "/Volumes/Folder" as text
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
repeat with each_message in these_messages
repeat with theAttachment in each_message's mail attachments
set originalName to name of theAttachment
set savePath to attachmentsFolder & ":" & originalName
try
save theAttachment in savePath
end try
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
I have created a simple example that fails to run:
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
repeat with each_message in these_messages
set theSubject to subject of each_message
display dialog theSubject
end repeat
end tell
end perform mail action with messages
end using terms from
In the second script, the "display dialog theSubject" never displays. In the first script the failure happens when trying to execute the "repeat with theAttachment in each_message's mail attachments" line. I have tried sending a "display dialog" in front of the lines and behind them. The script never gets to the second "display dialog" call which tells me the failure is crashing the script at that point.
Does anyone know what is going on with AppleScript or where I find the AppleScript Mail reference?
MacBook Pro 16″, macOS 14.1