Skip to content

Instantly share code, notes, and snippets.

@moyashi
Last active October 29, 2019 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moyashi/9073f27e4b673e1e44c668b75b838e8f to your computer and use it in GitHub Desktop.
Save moyashi/9073f27e4b673e1e44c668b75b838e8f to your computer and use it in GitHub Desktop.
iOS 13.2で搭載されたメッセージ着信時の読み上げ機能(AirPods使用時限定)を活用するため、macOSのメッセージアプリから機械的にメッセージを送るスクリプト
#!/usr/bin/ruby
# iOS 13.2で搭載されたメッセージ着信時の読み上げ機能(AirPods使用時限定)を活用するため
# macOSのメッセージアプリから機械的にメッセージを送るスクリプト
# ■使い方
# 引数としてテキストを渡す(空白が入る場合はダブルクォーテーションで括る)
# send_message.rb "なんかテキスト"
#
# 標準入力としてテキストを渡す
# pbpaste | send_message.rb
#自分のメッセージ(iMessage)アドレスを指定
sendto = "hogehoge@hoge.com"
if (ARGV.length == 0) then
lines = []
while line = gets
lines << line
end
mes = lines.join
if (mes == "\n") then
puts "No text to send"
exit
end
elsif (ARGV.length == 1) then
mes = ARGV[0]
else
puts "No arguments"
exit
end
script = <<"EOS"
tell application "Messages"
set targetBuddy to "#{sendto}"
set targetService to id of 1st service whose service type = iMessage
set textMessage to "#{mes}"
set theBuddy to buddy targetBuddy of service id targetService
send textMessage to theBuddy
end tell
EOS
IO.popen("osascript", "r+") {|io|
io.puts script
io.close_write
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment