2017-05-12 3 views
0

applescript의 전자 메일에 첨부 파일을 여러 개 추가하려고합니다. 제목을 폴더와 주 번호로 설정합니다. Apple Mail 응용 프로그램, 여러 첨부 파일 추가

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" 
 
\t set folderPath to folder ((get (path to home folder) as Unicode text) & "Documents:folder" as Unicode text) 
 
\t set thefList to "" 
 
\t set fcount to 1 
 
\t repeat 
 
\t \t try 
 
\t \t \t set theFile to ((file fcount) in folderPath as alias) 
 
\t \t \t set theFile to name of theFile 
 
\t \t \t if thefList is "" then 
 
\t \t \t \t set thefList to theFile 
 
\t \t \t else 
 
\t \t \t \t set thefList to thefList & " 
 
" & theFile 
 
\t \t \t end if 
 
\t \t \t set fcount to (fcount + 1) 
 
\t \t on error 
 
\t \t \t set fcount to (fcount - 1) 
 
\t \t \t exit repeat 
 
\t \t end try 
 
\t end repeat 
 
\t 
 
\t --return thefList 
 
\t set theAttachment to theFile 
 
end tell 
 

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

 

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

그것은 첨부 파일을 추가하지 않지만 이메일을 보내고있다.

프로그램을 수정하여 첨부 파일을 추가하려면 어떻게해야합니까?

답변

0

일반적인 오해가있다는 :

메시지의 첨부 파일이 아닌 문자열 파일 이름에 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:"[email protected]", subject:theSubject, content:rSpace} 
    tell theMessage 
     make new to recipient with properties {address:"[email protected]"} 
     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 
+0

대단히 감사합니다! –