Is it there any way to force attachments download from server before resuming the AppleScript? The problem is that until you physically open the mail message, it doesnt completely download the attachments and, consequently, any AppleScript intended to save the attachments in any place, would fail and in fact, fails
Mail attachments have a downloaded property that tells you if they’ve been downloaded or not, but there’s no specific way I can see to force it if, other than directly saving it to disk (which kind of requires its downloaded from the server first).
Just get
it. It is a boolean. If true then proceed, if false then wait and try again.
Wow! Why I didn’t think about this!. Great idea. Thanks Camelot
Notwithstanding, I lazily have asked ChatGPT how to save the message, sending a copy of my complete script and telling your idea, and surprisingly, it has perhaps(?) improve the trick. Hasn’t it?
tell application "Mail"
set theMessages to selection
set mercadonaTicketsFolder to POSIX file "/Users/me/Documents/documentos/€/Mercadona/" as alias
tell application "Finder" to open mercadonaTicketsFolder
repeat with theMessage in theMessages
-- Forzar la descarga accediendo al contenido del mensaje
set messageContent to content of theMessage
-- Ahora procesamos los adjuntos
repeat with theAttachment in theMessage's mail attachments
try
set originalName to name of theAttachment
set savePath to (mercadonaTicketsFolder as rich text) & originalName
save theAttachment in file savePath
set read status of theMessage to true
on error errMsg
display dialog "Error guardando adjunto: " & errMsg buttons {"OK"} default button 1
end try
end repeat
end repeat
end tell