【问题标题】:Writing an Apple Script to send emails from numbers编写 Apple 脚本以从数字发送电子邮件
【发布时间】:2017-01-04 07:21:43
【问题描述】:

所以我正在尝试编写一个苹果脚本,将电子邮件发送到选定的数字信息块。

数字的格式如下:

这是我的苹果脚本:

on run {input, parameters}
if the class of input is not string then set input to input as string

set currentRow to my theSplit(input, "*")

set row to 1

repeat while row <= (count of currentRow)

    set fullInput to {}
    set fullInput to my theSplit(item row of currentRow, "  ")
    set row to row + 1

    set theName to ""
    if item 2 of fullInput is "" then
        set theName to item 1 of fullInput
    else
        set theName to item 2 of fullInput
    end if

    set theContent to "Hello " & theName & ", Email Body"

    tell application "Mail"
        set thisMessage to make new outgoing message with properties {subject:"HTML5 Game Sponsorships", content:theContent}
        tell thisMessage
            make new to recipient with properties {address:(item 3 of fullInput)}
            set visible to true

        end tell
    end tell

end repeat

end run

on theSplit(theString, theDelimiter) 将 oldDelimiters 设置为 AppleScript 的文本项分隔符 将 AppleScript 的文本项分隔符设置为 theDelimiter 将 theArray 设置为 theString 的每个文本项 将 AppleScript 的文本项分隔符设置为 oldDelimiters 返回数组 结束分裂

脚本正确创建电子邮件,正确格式化信息。但是当数字中的行不包含名称时,问题就出现了。当名称为空时,脚本假设说 Hello 'Company Name'。

它会这样做,但出于某种原因它写道:

你好 '公司名称',

它不应该在下一行。我认为这是因为有一些不可见的字符代表我需要以某种方式删除的换行符。奇怪的是,它只在第二次需要使用公司名称时才这样做,第一次就正确了。

我希望这是有道理的,非常感谢任何帮助。

【问题讨论】:

  • 您能否发布您的 AppleScript 代码的屏幕截图,而不是发布实际代码本身,以便其他人可以复制代码以在脚本编辑器中使用它来测试和解决您的问题?
  • 你去!我最初在 Apple 社区上发布了这个,当我粘贴代码时,它搞砸了所有格式,所以我只是把它做成了一个图像。好久没回音了,就把帖子复制过来了。

标签: applescript spreadsheet


【解决方案1】:

您可以尝试使用以下方法来修剪公司名称中的回车符:

set theName to characters 2 thru -1 of (item 1 of fullInput)

这将它设置为第二个直到最后一个字符。 (-1 表示最后一个,-2 是倒数第二个等等。)

【讨论】:

  • 这可行,但它第一次发布公司名称时没有回车。我最终只是在开始处放了另一列单元格作为缓冲区。运行良好,并使用我的脚本发送了大约 100 封电子邮件。
猜你喜欢
  • 2011-09-16
  • 2011-04-28
  • 1970-01-01
  • 2018-09-29
  • 1970-01-01
  • 2012-08-25
  • 1970-01-01
  • 2020-11-03
  • 2018-01-15
相关资源
最近更新 更多