I'm hoping to programmatically send files via imessage
, yet cannot figure out how to send a file object via the API.
This script send a message to a specified user with the file path:
imessage() {
file="$PWD/$2";
osascript -e 'tell application "Messages" to send '\"$file\"' to buddy '\"$1\"';
}
How can I send the actual file? A pointer to the docs for this would also be helpful.
It seems that the easiest way to do this is to create an AppleScript file and call this via bash as demonstrated here 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 script
imessage() {
osascript sendmessage.scpt "$PWD/$2" "$1";
}