如何使用 AppleScript 发送图片

How to send pictures using AppleScript

我制作了一个向人们发送消息的脚本。我也希望能够通过这个脚本发送图片。

on run
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy "18008888888" of targetService

        repeat 3 times
            send "/Users/ADMIN/Desktop/photo.png" to 
targetBuddy
        end repeat

    end tell
end run

将照片的目录放在引号中会使发送的消息成为字符串,去掉引号会导致错误。

您需要 file 参考资料。尝试

send POSIX file "/Users/ADMIN/Desktop/photo.png" to targetBuddy

set filePath to (path to desktop as text) & "photo.png"

tell application "Messages"
    set targetService to 1st service whose service type = iMessage
    set targetBuddy to buddy "18008888888" of targetService

    repeat 3 times
        send file filePath to targetBuddy
    end repeat
end tell