だから私は本質的に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
これは、新しい会話を開始するときに機能しないことを除いて、ほとんどの部分で機能します。メッセージ内で会話していない番号に対してスクリプトを実行すると、「メッセージに受信者がいません」というポップアップ警告が表示されます。ただし、これによりその人との会話が作成され、同じスクリプトを再度実行すると機能します。
2回目はうまくいくかと思ったのですが、どういうわけか新しい会話を作る方法があるはずですが、これまでAppleScriptやスクリプト言語を実際に使ったことがないので、どうすればいいのかわかりません。
編集:投稿した直後、私は大まかな回避策を考えました。メッセージを送信する直前に空の文字列を送信すると、新しい会話を作成でき、既存の会話で機能します。
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
これは機能しますが、これよりも優れた/よりエレガントなソリューションがあると思います。
それを行うには多くの方法があります。
最初の例:
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
2番目の例:
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
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加