【问题标题】:Applescript - drag/drop file attachment to open new emailApplescript - 拖放文件附件以打开新电子邮件
【发布时间】:2010-11-22 17:43:28
【问题描述】:

任何人都知道 Applescript 片段,它将打开一封新电子邮件,其中包含已拖放到 Applescript 脚本上的文件附件? (Google 没有提供帮助。)

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

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 并将其添加到下方。

【问题讨论】:

    标签: macos email applescript


    【解决方案1】:

    您正在寻找的是 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
    

    在 Matt Neuberg 的书AppleScript:权威指南中有更多关于handlers 的详细信息。

    【讨论】:

    • 由于某种原因不想工作;它会打开一封新电子邮件,但不附加文件。
    【解决方案2】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 2014-04-25
      • 2020-09-04
      • 2011-09-02
      • 2021-10-03
      相关资源
      最近更新 更多