bash - 使用 AppleScript + bash 发送文件对象

标签 bash applescript imessage

我希望通过 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";
}

关于bash - 使用 AppleScript + bash 发送文件对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54874497/

相关文章:

bash - 在 mac OS X 中登录时运行脚本

linux - 如何在 bash 中使用 $find 命令抑制文件夹排序

bash - 使用 shell 脚本删除相同的文件

macos - 直接打开一个文件到emacs(通过双击)

iphone - iOS6 中的短信通知

linux - 从 bash 脚本中的行号开始读取行

objective-c - 可编写脚本的应用程序示例

applescript - 如何使用 AppleScript 启动 Automator 应用程序?

ios - iPhone 消息应用程序的这个上滑菜单是如何实现的?

swift - InsertAttachment withAlternateFilename 在 iOS 10 中不起作用