1

I have an automator workflow starting with "Take ScreenShot" to take screenshot and paste to clipboard.

Following that I have

set theTime to time string of (current date)

tell application "Messages"
    set iMessageService to 1st service whose service type = iMessage
    set imessagebuddy to buddy "imessagebuddy@domain.com" of iMessageService
    send theTime to imessagebuddy
end tell

I want to include the screenshot in the message with the time.

1
  • While one could manually paste or use UI Scripting to paste an image from the clipboard into the Messages app, if you want to do it programmatically without UI Scripting, and believe me you do not want to use UI Scripting for this, then the image contents of the clipboard needs to be written to a disk file to be sent in Messages. It can be a temporary file but it still need to be on disk not the clipboard to send it. – user3439894 Feb 23 '18 at 6:11
3

Here is a way to take the screenshot from the clipboard and send it in Messages.

Example AppleScript code:

if ((clipboard info) as string) contains JPEG picture then

    set jpgData to the clipboard as JPEG picture        
    set fileName to "/tmp/IMG_" & (random number from 1000 to 9999) & ".JPG" as string

    try
        set thisFile to open for access POSIX file fileName with write permission
        write jpgData to thisFile
        close access thisFfile
    on error
        close access thisFile
        return
    end try

    set theTime to time string of (current date)
    set thePicture to POSIX file fileName as alias

    tell application "Messages"
        set iMessageService to 1st service whose service type = iMessage
        set imessagebuddy to buddy "imessagebuddy@domain.com" of iMessageService
        send theTime to imessagebuddy
        send thePicture to imessagebuddy
    end tell

    tell application "System Events"
        delete alias fileName
    end tell

end if

Note: The example AppleScript code is just that and does not employ any other error handling then what's shown and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .