最近在使用脚本自动编译上传App到iTunes,到最后一步有个需求,就是需要把上传结果及时通知多个人。一开始想使用Mail。但是又感觉用Mail有点太重了。所以打算用一个轻量级的解决方案——将上传结果,通过iMessage,直接发送到手机上。
发送iMessage需要使用Apple Script。
tell application "Messages"
send "iMessage的内容" to buddy "foo@helloworld.com" of (service 1 whose service type is iMessage)
end tell
或者直接发送到手机号码也没有问题
tell application "Messages"
send "iMessage的内容" to buddy "+8612345678901" of (service 1 whose service type is iMessage)
end tell
如果你是个土豪,也可以通过短信方式发送
tell application "Messages"
send "iMessage的内容" to buddy "+8612345678901" of service "SMS"
end tell
OK,然后我们需要在Shell中调用这段Apple Script,所以把内容和发送的对象作为参数传入。最后的脚本就是
on run {receiver, message}
tell application "Messages"
send message to buddy receiver of (service 1 whose service type is iMessage)
end tell
end run
将Apple Script保存为类似sendMessage.scpt
在Shell中调用Apple Script
然后在Shell脚本中,用这样的方法来调用:
$ osascript sendMessage.scpt "+8612345678901" "iMessage的内容"
好了,全部搞定!