2010-11-22 62 views
0

任何人都知道Applescript会使用已在Applescript脚本上拖放的文件附件打开一封新邮件? (谷歌一直没有帮助。)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并在下面添加。

回答

1

被赋予这对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 
2

你在找什么是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:"[email protected]"} 
      end tell 
     end repeat 
    end tell 
end open 

还有很多更详细的关于handlers在马特·纽伯格的书的AppleScript权威指南

+0

这并不希望出于某种原因;它会打开一封新邮件但不会附加该文件。 – markratledge 2010-11-28 20:28:14