daniil_romanov (daniil_romanov) wrote in ru_mac,
daniil_romanov
daniil_romanov
ru_mac

Mail.app и AppleScript

в почту регулярно приходят письма с вложениями от 1 до 5 мб и хранить их в почте тяжело.
на просторах интеренета нашел скрипт для сохранения вложения из письма.
настроил правило: от адресата перемещать в папку и запустить скрипт.
проблема в том что вложения не сохраняются!
скрипт ниже.
[Скрипт]

on perform_mail_action(ruleData)

set attachmentsFolder to ((path to home folder as text) & "Documents:Attachments") as text

set subFolder to name of |Rule| of ruleData as text

tell application "Finder"

if not (exists folder subFolder of folder attachmentsFolder) then

make new folder at attachmentsFolder with properties {name:subFolder}

end if

end tell

tell application "Mail"

set selectedMessages to |SelectedMessages| of ruleData

repeat with theMessage in selectedMessages

set {year:y, month:m, day:d, hours:h, minutes:min} to theMessage's date sent

set timeStamp to ("" & y & "-" & my pad(m as integer) & "-" & my pad(d) & "-" & my pad(h) & "-" & my pad(min))

repeat with theAttachment in theMessage's mail attachments

set originalName to name of theAttachment

set savePath to attachmentsFolder & ":" & subFolder & ":" & timeStamp & " " & originalName

try

save theAttachment in savePath

end try

end repeat

end repeat

end tell

end perform_mail_action

on pad(n)

return text -2 thru -1 of ("00" & n)

end pad

Tags: applescript automator, mail|другие почтовые программы, yosemite
Subscribe

  • Как меня мак ось поимела

    Обновился до 15.5 ДВА вопроса теперь :) Почему-то файлы с камеры теперь воспринимаются как вражеские. Не, я часок посидел, каждому файлу разрешил и…

  • Убийца траффика

    Обратил внимание, что сеть валится, полез в роутер, а там мой ноут разгулялся... Сосет и сосет чего-то в себя Апдейты ему не нужны, он на интеле. Да…

  • Из App Store пропала страница покупок.

    На старом MacBook Pro (2011), из App Store пропала страница покупок. Это так из-за того, что ОС устарела (macOS 10.3)? Соответственно, не могу…

  • Post a new comment

    Error

    Comments allowed for members only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 5 comments