【发布时间】: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 社区上发布了这个,当我粘贴代码时,它搞砸了所有格式,所以我只是把它做成了一个图像。好久没回音了,就把帖子复制过来了。