Mail kreeg een fout: AppleEvent-handler mislukt. (Mail error: AppleEvent-handler failed)
There is an attachment. The count gives an error. See underline
set walletmobileAccount to "demomycardwallet"
tell application "Mail"
set attachmentsFolder to "Volumes:Macintosh HD:Users:did4you:Downloads:" as rich text
set thereIsFoto to false
set fileCounter to 1
set logoFile to ""
set pictureFile to ""
-- display dialog "attachmentsFolder = " & attachmentsFolder
set theMessage to message 2 of mailbox "INBOX" of account walletmobileAccount
if (count of (theMessage's mail attachments)) > 0 then
repeat with theAttachments in theMessage's mail attachments
set originalName to name of the theAttachments
-- display dialog "Naam van attachment = " & originalName
set foto to originalName
if fileCounter = 1 then
set logoFile to originalName
end if
if fileCounter = 2 then
set pictureFile to originalName
end if
set savePath to attachmentsFolder & originalName
save theAttachments in savePath
do shell script "cp -f -R Users/did4you/Downloads/" & quoted form of originalName & " Users/did4you/Documents/MaakZP/Bijlagen/"
do shell script "rm -R Users/did4you/Downloads/" & quoted form of originalName
set fileCounter to fileCounter + 1
end repeat
-- display dialog "Foto : " & logoFile
-- display dialog "pictureFile : " & pictureFile
set thereIsFoto to true
end if -- are there any attachments
end tell