如何将对话框的输出发送到AppleScript中的电子邮件地址

时间:2014-09-02 03:30:57

标签: macos applescript

我希望能够将对话框的输出发送到我的电子邮件中。做这种事的最好方法是什么?

这有点像这样:

repeat
   display dialog "Enter some text:" buttons {"Git Goin"} default answer ""
   set theNewInfo to text returned of result
   if theNewInfo ≠ "" then exit repeat
end repeat

它是一个非常简单的概念证明脚本,但我想要的是如下:当他们在对话框中输入任何文本时,将该文本发送到我的电子邮件,无论它包含什么。会说" NewInfo"并且正文将包含输入对话框的文本

1 个答案:

答案 0 :(得分:0)

你应该发布你拥有的代码......太多的问题仍然无法可靠地回答你。你想发送什么电子邮件?电子邮件addy?学科?身体?等等 基本上,您捕获对话框的结果,然后将其放入“mailto:”URL字符串,然后在URL上使用“打开位置”。这应该足以让你入门:

set dialogResult to display dialog "Enter the subject" default answer "My subject" buttons {"me@example.com", "you@example.com"} default button 1

set theAddress to button returned of dialogResult
set theSubject to text returned of dialogResult
set theBody to "This%20is%20the%20body%20text:%0AMore%20text"

-- Must encode entities, spaces as %20 and line breaks as %0A (%0D%0A), etc.
set theSubject to findReplace(" ", "%20", theSubject)
set theSubject to findReplace(return, "%0A", theSubject)

set theURL to "mailto:" & theAddress & "?subject=" & theSubject & "&body=" & theBody

open location theURL

on findReplace(f, r, s)
    set otid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to f
    set s to text items of s
    set AppleScript's text item delimiters to r
    set s to s as string
    set AppleScript's text item delimiters to otid
    return s
end findReplace