Приложение Apple Mail, добавление нескольких вложений

Я пытаюсь добавить несколько вложений в электронное письмо в applecript. Я установил тему для папки и номер недели в верхней части.

set {b, c} to {"1/1/1000", 364876}
set {year:yy, month:mm, day:dd} to (current date)
set yy to text 3 thru 4 of (yy as text)
set d to ((((current date) - (date b)) div days + c) div 7) + 1
set e to ((((date ("1/1/" & (year of the (current date)) as string)) - (date b)) div days + c) div 7) + 1
set weekCode to (yy & (d - e) as text)
set rSpace to "
"
set theSubject to "folder Week " & (text 3 thru 4 of weekCode)

tell application "Finder"
 set folderPath to folder ((get (path to home folder) as Unicode text) & "Documents:folder" as Unicode text)
 set thefList to ""
 set fcount to 1
 repeat
  try
   set theFile to ((file fcount) in folderPath as alias)
   set theFile to name of theFile
   if thefList is "" then
    set thefList to theFile
   else
    set thefList to thefList & "
" & theFile
   end if
   set fcount to (fcount + 1)
  on error
   set fcount to (fcount - 1)
   exit repeat
  end try
 end repeat
 
 --return thefList
 set theAttachment to theFile
end tell

repeat (fcount - 1) times
 set rSpace to "
" & rSpace
end repeat


tell application "Mail"
 activate
 set theMessage to make new outgoing message with properties {visible:true, sender:"my@email.com", subject:theSubject, content:rSpace}
 
 
 tell theMessage
  make new to recipient with properties {address:"their@email.com"}
  set acount to 1
  repeat fcount times
   
   try
    make new attachment with properties {file name:(paragraph acount of thefList)} at after the last word of the paragraph acount
    set message_attachment to 0
   on error errmess -- oops
    log errmess -- log the error
    set message_attachment to 1
   end try
   log "message_attachment = " & acount
   set acount to (acount + 1)
  end repeat
  
  send
 end tell
end tell

Это не добавление вложений, а отправка электронного письма.

Как я могу исправить программу, чтобы добавить вложения?

1 ответ

Существует общее недоразумение:

Вложение сообщения должно быть alias ссылка на файл, а не имя файла строки.

Код для получения файлов и создания новых строк в сообщении можно сократить до

set documentsFolder to path to documents folder
tell application "Finder"
    set folderPath to folder "folder" of documentsFolder
    set attachmentList to files of folderPath as alias list
end tell

set rSpace to ""
repeat (count attachmentList) - 1 times
    set rSpace to rSpace & return
end repeat

и код для создания сообщения также может быть уменьшен до (я закомментировал send линия)

tell application "Mail"
    activate
    set theMessage to make new outgoing message with properties {visible:true, sender:"my@email.com", subject:theSubject, content:rSpace}
    tell theMessage
        make new to recipient with properties {address:"their@email.com"}
        set acount to 1
        repeat with anAttachment in attachmentList
            make new attachment with properties {file name:anAttachment} at after the last word of the paragraph acount
            log "message_attachment = " & acount
            set acount to (acount + 1)
        end repeat

        -- send
    end tell
end tell
Другие вопросы по тегам