AppleScript для Mail.app, чтобы дублировать исходящее сообщение и отправить как вновь отформатированное сообщение - PullRequest
0 голосов
/ 04 сентября 2011

Так что я искал способ сделать следующее, последовательно в Mail.app, используя AppleScript:

  1. перехватить исходящее сообщение (назовем это "A")
  2. сделать и точно дублировать сообщение (назовем это «B») из исходящего сообщения «A»
  3. форматировать текст / содержание и т. Д. Этого нового сообщения ("B")
  4. отправить это вновь отформатированное сообщение ("B")
  5. не обращайте внимания на исходное («А»).

Зачем мне делать что-то, что кажется таким отсталым?

  • Mail.app от Apple удивительно не форматирует исходящее содержимое ваших сообщений.
  • Путем выполнения основного сообщения> Предпочтения> и т. Д. И т. Д. Изменяется только стиль шрифта сообщения, которое вы видите через Mail.app. Когда получатель получает сообщение, выбирается шрифт клиента по умолчанию (который может быть отвратительным Times New Roman для таких клиентов, как Outlook).

Так почему бы просто не попросить Applescript, который напрямую форматирует ваше исходящее сообщение?

Все еще изучаю веревки с помощью Applescript, поэтому буду очень признателен, если кто-нибудь сможет подготовить AppleScript, который выполняет запрошенный запрос.

Мое намерение - вызвать Applescript, когда я нажму "Отправить сообщение" (через прекрасного Маэстро Клавиатуры).

Вот код скелета яблочного скрипта, который я мог бы придумать:

set theFont to "Lucida Sans, Lucida Sans Unicode, Lucida Grande, Verdana, Arial"
set theSize to 12
tell application "Mail"
    -- 1. intercept an outgoing message
    set outMsg to front outgoing message


    -- 2. make and exact duplicate of this outgoing message
    -- need a little help with extracting...
            set fmtMsg to make new outgoing message with properties 
        {   sender:,
            subject:”Convert”, 
            content:”Please convert and send”
            message signature:,
            to recipient:,
            cc recipient:,
            bcc recipient:
        }


    tell fmtMsg
                    -- 3. format the text/content etc of this newly made message
        set font of content to theFont
        set size of content to (theSize)
        -- set visible to true

                    -- 4. send this newly formatted message
        send

                    -- 5. disregard the original one.
                    -- help?
    end tell


end tell

Приветствие.

1 Ответ

1 голос
/ 04 сентября 2011

Я не так много работал с Mail, но я написал скрипт, который должен выполнять эту работу ...

set the mail_recipient to the text returned of (display dialog "To:" default answer "")
set the mail_subject to the text returned of (display dialog "Subject:" default answer "")
set the mail_content to the text returned of (display dialog "Enter your message here (for a new line type \"\\n\"):" default answer "")
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\\" & "n"
set this_text to every text item of the mail_content
set AppleScript's text item delimiters to return
set the mail_content to this_text as string
tell application "Mail"
    tell (make new outgoing message with properties {visible:true, subject:mail_subject, content:mail_content})
        make new to recipient at the end of to recipients with properties {address:mail_recipient}
        send
    end tell
end tell

Я не добавил проверку ошибок в скрипте (проверьтедействительный адрес получателя).

Как вы сказали, вы не можете изменить шрифт получателя;это может считаться преследованием.

Если этот сценарий не подходит, просто дайте мне знать, и я изменю его для вас.:)

ОБНОВЛЕНИЕ: Я только что прочитал об использовании AppleScript с Mail и только что понял, что Mail имеет огромные ограничения в отношении AppleScript.Я думаю, что вам лучше всего использовать GUI Scripting.Этот скрипт довольно хакерский, но он должен работать.

tell application "System Events" to tell process "Mail" to set the mail_subject to (get the value of the first text box)
tell application "Mail" to set this_message to the content of the first message of mailbox "Sent" whose subject is the mail_subject

ОБНОВЛЕНИЕ 2:

tell application "System Events"
    tell process "Mail"
        set the mail_recipient to (get the value of the first text field)
        set the mail_subject to (get the value of the fourth text field)
        set the mail_content to (get the value of the last text field)
        my create_new_message(mail_recipient, mail_subject, mail_content)
    end tell
end tell

on create_new_message(recipient, subject, content)
    tell application "Mail"
         quit saving no
         activate
         tell (make new outgoing message with properties {subject:|subject|, content:|content|)
             make new recipient at the end of to recipients with properties {address:|recipient|}
             send
         end tell
    end tell
end create_new_message
...