基本のコード
iMessageを自動で送信できないか考えていて、AppleScriptでできないかとやってみた。
imessage.scpt
tell application "Messages"
set targetBuddy to "iMessageの送信先(メールアドレスor電話番号)"
set targetService to id of 1st service whose service type = iMessage
set textMessage to "送信するメッセージ"
set theBuddy to buddy targetBuddy of service id targetService
send textMessage to theBuddy
end tell
これでわりと簡単に送信できた。
1秒に1回送るようにしてみる
imessage.scpt
tell application "Messages"
set targetBuddy to "iMessageの送信先(メールアドレスor電話番号)"
set targetService to id of 1st service whose service type = iMessage
repeat
set textMessage to "送信するメッセージ"
set theBuddy to buddy targetBuddy of service id targetService
send textMessage to theBuddy
delay 1
end repeat
end tell
ちなみに、
delay 1
の行を、
delay (random number from 1 to 30)
とかにすれば、1〜30秒の間に1回送信される。
送るメッセージをランダムにしてみる
imessage.scpt
tell application "Messages"
set targetBuddy to "iMessageの送信先(メールアドレスor電話番号)"
set targetService to id of 1st service whose service type = iMessage
set rand to random number from 1 to 4
if rand = 1 then
set message to "うっひょー"
end if
if rand = 2 then
set message to "ほげほげ"
end if
if rand = 3 then
set message to "ヌベジョンヌゾジョンベルミッティスモゲロンボョ"
end if
if rand = 4 then
set message to "うぇーい"
end if
set textMessage to message
set theBuddy to buddy targetBuddy of service id targetService
send textMessage to theBuddy
end tell
数字と一緒に送ってみる
imessage.scpt
tell application "Messages"
set targetBuddy to "iMessageの送信先(メールアドレスor電話番号)"
set targetService to id of 1st service whose service type = iMessage
set rand to random number from 1 to 100
set textMessage to rand & "億ほしい"
set theBuddy to buddy targetBuddy of service id targetService
send textMessage to theBuddy
end tell