【发布时间】:2020-08-04 23:17:22
【问题描述】:
我在连接到 iPhone 的 MacBook 笔记本电脑上使用 AppleScript 发送一大堆单独的文本消息。
如果我创建一条消息,将其手动复制粘贴到消息中,然后手动发送,一次一条消息(复制粘贴消息、复制粘贴电话号码、发送)一切正常。我可以轻松地格式化草稿中的消息,并且保留格式。如果我尝试通过脚本执行此操作,则换行符会丢失。
想要的消息:
大家好,
这将是周五上午 10 点举行的一次特别会议。 请拨入组会议,接入线路xxxxxxxxxxx
讨论主题:季度销售。
大家干得好,本季度销售额达到顶峰;所有 得到加薪,yippee。会议上分享的细节。
再次感谢大家
苏珊,
销售经理
这就是它的到达方式。
大家好,这将是一个特别的会议 周五,上午 10 点。请拨入组会议,接入线路 xxxxxxxxxxx 讨论主题:季度销售。大家干得好, 本季度销售额达到顶峰;我们都在加薪, 伊皮。会议上分享的细节。再次感谢所有的苏珊, 销售经理
这是appleScript:
set textMessage to "Hello Everybody,\n\nThis is going to be a special meeting taking place
on Friday, 10AM. Please call in to the group meeting, access line xxxxxxxxxxx\n\nTopic
of Discussion: Quarterly Sales. \n\nGreat Job everybody, Sales are thru the roof this
quarter; We're all getting pay raises, yippee. Details shared at the meeting.
\n\nAgain, thanks to all \n\nSusan, \nSales Manager\n"
set phonelist to {"1999-555-6850", "1999-555-9496", "1999-555-7170", "1999-555-4445",
"1999-555-1182", "1999-555-7463", "1999-555-1809", "1999-555-8916", "1999-555-5139",
"1999-555-5252", "1999-555-6646", "1999-555-3642", "1999-555-2437", "1999-555-0755",
"1999-555-8732", "1999-555-6202", "1999-555-0310", "1999-555-7410", "1999-555-3300",
"1999-555-0655"}
set i to 0
activate application "Messages"
tell application "System Events" to tell process "Messages"
repeat with indPhone in phonelist
set i to i + 1
key code 45 using command down -- press Command + N to start a new window
keystroke indPhone -- input the phone number
delay 1
key code 36
key code 36 -- press Enter to focus on the message area
keystroke textMessage -- type some message
delay 1
key code 36 -- press Enter to send
say i
delay 5 -- Audio plus delay = success tracking.
-- If for some reason something goes wrong, I know where I am.
-- e.g. phone rings during the process.
end repeat
end tell
注意:reference。
注意#2。哦,请注意这不是实际发送的消息。这只是 StackOverflow 的一个人为示例。收到消息的观众只是不明白当有人回复群组消息时会发生什么。他们只是不明白,叹息。所以不,组文本页面不是答案。我们需要单独的短信,每人一条。但是谢谢你的建议。通常,我们使用这种技术一次只发送不到 100 条消息。
当它作为脚本运行时,为什么我们会丢失 \n 格式?如果您在 Mac 上运行这个完全相同的脚本,您会看到相同的结果吗?
编辑:我将分享一些手机屏幕截图。
我想要的(通过手动复制并粘贴到消息应用中创建):
这是我使用上面的脚本得到的结果 (/n/n):
这就是我使用 RobC & return & 技术得到的结果。 (见 cmets)
【问题讨论】:
-
不是每个新行都会导致消息被发送吗?看起来你最终会得到每一行都是它自己的信息。
-
而不是
\n使用& return &在您想要换行的地方连接文本。例如:set textMessage to "Hello Everybody," & return & return & "This is going to be..."。或者改用& linefeed &,例如set textMessage to "Hello Everybody," & linefeed & linefeed & "This is going to be..." -
@Robc 查看我的帖子的编辑。这个也是失败的。欣赏这个想法。还有其他人吗?这里的问题是我的手机一次会发送 100x7 = 700 条短信。你认为这会让我的电话服务提供商大吃一惊吗?
-
很确定我在七个版本前尝试过。但我肯定会再试一次。失败。它只是回显 html 命令,并显示:
<html><p>Hello Everybody,</p><p>This is going to be a special meeting taking place on Friday, 10AM. ...。我在有和没有<html>的情况下都试过了,都失败了。 -
是否可以使用诸如'0x2028'(NSLineSeparatorCharacter)之类的字符?又名,软回报?
标签: macos applescript sms message