Mailで添付ファイルを自動保存
https://discussionsjapan.apple.com/thread/10125572
(Mailで添付ファイルを自動リネーム&自動保存)
https://discussionsjapan.apple.com/message/100746770
(Mailで添付ファイルを自動リネーム&自動保存(追加))
で質問させていただいたものです。
さらによろしくお願いします。
添付ファイルのファイルタイプ(拡張子)で保存先を振り分けるにはどうしたらいいでしょうか?少し自分でやってみたのですが、やはり駄目だったので、再び質問させていただきました。
PDFがほとんどで、時々JPGや他のファイルが届く事になると思うので、
PDFだったら ("MacintoshHD:Users:hoge:Desktop:添付ファイルA:" & fileName)
それ以外は ("MacintoshHD:Users:hoge:Desktop:添付ファイルB:" & fileName)
という設定にしたいです。
-----------(現状script)-----------
using terms from application "Mail"
on perform mail action with messages messageList
tell application "Mail"
repeat with eachMessage in messageList
set theSubject to subject of eachMessage
set attachmentList to (get mail attachments of eachMessage)
repeat with eachAttachment in attachmentList
set fileName to name of eachAttachment
set fileName to my setPref(theSubject) & "-" & my print_date() & "_" & fileName
save eachAttachment in file ("Macintosh HD:Users:hoge:Desktop:添付ファイル:" & fileName)
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
on print_date()
do shell script "date '+%y%m%d-%H_%M_%S'"
end print_date
on setPref(theText)
if theText contains "XX" then
set Pref to "XX"
else if theText contains "YY" then
set Pref to "YY"
else if theText contains "ZZ" then
set Pref to "ZZ"
else
set Pref to "Unknown"
end if
return Pref
end setPref
----------------------
iMac, Mac OS X (10.6.8)