6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【AppleScript】iMessageを自動送信する

Last updated at Posted at 2016-06-08

基本のコード

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
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?