yuwe
yuwe

Reputation: 159

How to send pictures using AppleScript

I made a script that sends messages to people. I also want to be able to send pictures through this script.

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

Putting the directory of the photo in quotations makes the message sent be a string, and taking away the quotes results in an error.

Upvotes: 0

Views: 1792

Answers (1)

vadian
vadian

Reputation: 285092

You need a file reference. Try

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

or

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

Upvotes: 1

Related Questions