使用AppleScript + bash发送文件对象

问题描述 投票:2回答:1

我希望以编程方式通过imessage发送文件,但无法弄清楚如何通过API发送文件对象。

此脚本使用文件路径向指定用户发送消息:

imessage() {
    file="$PWD/$2";
    osascript -e 'tell application "Messages" to send '\"$file\"' to buddy '\"$1\"';
}

我该如何发送实际文件?指向文档的指针也会有所帮助。

bash applescript imessage
1个回答
3
投票

似乎最简单的方法是创建一个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";
}
© www.soinside.com 2019 - 2024. All rights reserved.