我希望以编程方式通过imessage
发送文件,但无法弄清楚如何通过API发送文件对象。
此脚本使用文件路径向指定用户发送消息:
imessage() {
file="$PWD/$2";
osascript -e 'tell application "Messages" to send '\"$file\"' to buddy '\"$1\"';
}
我该如何发送实际文件?指向文档的指针也会有所帮助。
似乎最简单的方法是创建一个AppleScript文件并通过bash调用它,如https://gist.github.com/homam/0119797f5870d046a362所示。
AppleScript - sendmessage.scpt
on run argv
set filename to item 1 of argv
set buddyName to item 2 of argv
set attach to POSIX file filename
tell application "Messages" to send attach to buddy buddyName
end run
Bash脚本
imessage() {
osascript sendmessage.scpt "$PWD/$2" "$1";
}