代码之家  ›  专栏  ›  技术社区  ›  markratledge

Applescript-拖放文件附件以打开新电子邮件

  •  0
  • markratledge  · 技术社区  · 14 年前

    有人知道Applescript snip,它将打开一个新的电子邮件,其中的文件附件已在Applescript脚本上拖放?(谷歌没有提供帮助。)

    我找到了打开新电子邮件并提示输入文件附件的命令,

    set theAttachment to (choose file without invisibles)
    

    和剪子,允许硬编码到附件的路径,

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

    但不允许在Applescript脚本图标上拖放文件附件。

    编辑11/28/10: 找到并回答 MacScripter / AppleScript | OS X 并将其添加到下面。

    2 回复  |  直到 14 年前
        1
  •  2
  •   Ned Deily    14 年前

    你要找的是一个AppleScript open handler . 下面是一个简单的示例,通过为每个文件打开一个新的传出电子邮件来处理多个文件。可能会有很多变化:

    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:权威指南 .

        2
  •  1
  •   markratledge    14 年前

    是在 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