所以我正在创建一个基本上自动发送imessage的applescript。我现在的工作是:
on run {msg, phoneNum}
tell application "Messages"
set serviceID to id of 1st service whose service type = iMessage
send msg to buddy phoneNum of service id serviceID
end tell
end run
除了在开始新会话时不起作用外,这大部分都有效。当您将脚本运行到与消息中没有对话的号码时,会收到一条弹出警告,提示“您的消息没有任何收件人”。但是,这会创建与该人的对话,当您再次运行相同的脚本时,它会起作用。
我认为如果它第二次运行,必须有办法以某种方式创建一个新的对话,但是我从来没有真正使用过AppleScript或者之前的任何脚本语言,所以我不知道该怎么做。< / p>
编辑:发布后我立刻想到了一个粗略的解决方法。如果您在发送邮件之前发送了一个空字符串,则可以创建一个新会话,并且它可以与现有会话一起使用。
on run {msg, phoneNum}
tell application "Messages"
set serviceID to id of 1st service whose service type = iMessage
send "" to buddy phoneNum of service id serviceID
send msg to buddy phoneNum of service id serviceID
end tell
end run
虽然这有效,但我认为有一种比这更好/更优雅的解决方案。
答案 0 :(得分:3)
有很多方法可以做到。
第一个例子 :
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
第二个例子 :
tell application "Messages"
set targetBuddy to "+18001234567"
set targetService to id of 1st service whose service type = iMessage
repeat
set textMessage to "Hello pal!"
set theBuddy to buddy targetBuddy of service id targetService
send textMessage to theBuddy
delay (random number from 10 to 30)
end repeat
end tell
答案 1 :(得分:1)
我的解决方案是告诉Applescript按“ Command + N”,这是“开始新对话”的快捷键。
activate application "Messages"
tell application "System Events" to tell process "Messages"
key code 45 using command down -- press Command + N to start a new window
keystroke "<replace with phone number>" -- input the phone number
key code 36 -- press Enter to focus on the message area
keystroke "<replace with message>" -- type some message
key code 36 -- press Enter to send
end tell
此脚本将开始新的对话,并通过iMessage将消息发送到电话号码