Applescript - перетащить файл вложения, чтобы открыть новое письмо - PullRequest
0 голосов
/ 22 ноября 2010

Кто-нибудь знает фрагмент кода Applescript, который откроет новое письмо с вложенным файлом, который был перетащен в сценарий Applescript? (Google не помог.)

Я нашел команды, которые открывают новое письмо и запрашивают вложение файла,

set theAttachment to (choose file without invisibles)

и фрагменты кода, позволяющие жестко прописать путь к вложению,

set theAttachment to (((path to desktop) as string) & "myFile.jpg) as alias

но ни один из них не позволяет перетаскивать вложенный файл на иконку скрипта Applescript.

Редактировать 28.11.10: Найдено и ответить MacScripter / AppleScript | OS X и добавил его ниже.

Ответы [ 2 ]

2 голосов
/ 22 ноября 2010

Что вам нужно, так это открытый обработчик AppleScript . Вот простой пример, который обрабатывает несколько файлов, открывая новое исходящее электронное письмо для каждого. Возможны многие варианты:

on open what
    tell application "Mail"
        repeat with f in what
            set theAttachment to f
            set theMessage to make new outgoing message with properties {visible:true, subject:"My Subject", content:"My Body"}
            tell content of theMessage
                make new attachment with properties {file name:theAttachment} at after last paragraph
            end tell
            tell theMessage
                make new to recipient at end of to recipients with properties {name:"Some One", address:"someone@somewhere"}
            end tell
        end repeat
    end tell
end open

В книге Мэтта Нойберга есть много подробностей о handlers AppleScript: полное руководство .

1 голос
/ 28 ноября 2010

Было дано это на MacScripter / AppleScript | OS X и работает нормально:

property Myrecipient : "some email"
property mysubject : "some subject"
property EmailBody : "some body text"


on run
    tell application "Finder"
        set sel to (get selection)
    end tell
    new_mail(sel)
end run

on open droppedFiles
    new_mail(droppedFiles)
end open

on new_mail(theFiles)
    tell application "Mail"
        set newMessage to make new outgoing message with properties {visible:true, subject:mysubject, content:EmailBody}
        tell newMessage
            make new to recipient with properties {address:Myrecipient}
            tell content
                repeat with oneFile in theFiles
                    make new attachment with properties {file name:oneFile as alias} at after the last paragraph
                end repeat
            end tell
        end tell
        activate
    end tell
end new_mail
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...