Last active
October 29, 2019 06:48
-
-
Save moyashi/9073f27e4b673e1e44c668b75b838e8f to your computer and use it in GitHub Desktop.
iOS 13.2で搭載されたメッセージ着信時の読み上げ機能(AirPods使用時限定)を活用するため、macOSのメッセージアプリから機械的にメッセージを送るスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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