Tuesday, August 20, 2019

#1 2019-05-14 07:34:24 am

davidhmorgan
Member
From:: Sydney
Registered: 2014-08-20
Posts: 68

Messages – send multiple images

I'm trying to send multiple images in a single Message using AppleScript.

I can do it manually in iOS Messages by selecting images in Photos and sending them all in one message to a recipient. Otherwise on the Mac I can drag multiple images into the message pane of the Messages app. It seems to create multiple paragraphs, with each image on its own paragraph. Using AppleScript on the Mac however, I can only see how to send one image at a time. This results in a new notification for each image which is not ideal.

Looking at the Messages AppleScript dictionary, it seems multiple attachments can be added to rich text but I can't work out how to create a rich text object or a message object that can accept attachments or images. Any ideas?

Here is the code that can send images as multiple messages.

Applescript:


   tell application "Messages"
   set targetService to (1st service whose service type = iMessage)

   --This is the person's contact as text
   set MessengerContact to "1234 123 123"

   --This is the buddy that corresponds to this text
   set targetBuddy to buddy MessengerContact of targetService

   --The variable FileList is a list of aliases
   repeat with i from 1 to (count FileList)
       set targetAttach to item i of FileList
       send targetAttach to targetBuddy
   end repeat

   end

Last edited by davidhmorgan (2019-05-14 07:20:49 pm)

Offline

 

#2 2019-05-18 07:54:36 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 425

Re: Messages – send multiple images

To create a script that binds multiple files to a single message is a useless task. This is because the total size of files should not exceed 1-10 MB. Simply the server will refuse to send a huge message. Instead, you just need to build a text that includes a list of links to these files.  Building similar text with AppleScript is simple task. You create empty string, then add in loop each link to end of this string.

Maybe Messages allow adding links like nextLoopLinkString as URL. I did not try, I do not know. If not, add them as plain text. Use & return at the end of each added link.

Last edited by KniazidisR (2019-05-18 08:22:43 pm)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

#3 2019-05-19 08:27:45 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 411

Re: Messages – send multiple images

I don't have an answer on how to attach the files, but in reply to KniazidisR's response - a lot of texted image jpg's are 100k or less. You could put 100 of them on a max 10 MB text message. For all we know, his goal is to attach 2 ≈30k images to each message. Doing so is not a "useless task." I text multiple images in one message to people via UI on my phone all the time and it's never caused a problem I'm aware of.

As he noted, he can accomplish what he wants via the UI, so I don't think dismissing what he wants as impractical is likely an accurate criticism.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#4 2019-05-20 01:30:20 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 425

Re: Messages – send multiple images

t.spoon wrote:

I don't have an answer on how to attach the files, but in reply to KniazidisR's response



Okay. Once you insist ...

Applescript:


set theImagesAliasList to (choose file of type {"public.image"} with multiple selections allowed)

set theImagesPosixList to {}
repeat with i from 1 to (count of theImagesAliasList)
   set theItem to item i of theImagesAliasList
   tell application "System Events" to set theItem to (POSIX path of theItem)
   set end of theImagesPosixList to POSIX file theItem
end repeat

tell application "Messages" to activate
tell application "System Events" to tell application process "Messages"
   
   click menu item "New Message" of menu 1 of menu bar item "File" of menu bar 1
   click text field "To:" of scroll area 3 of splitter group 1 of window "Messages"
   keystroke "1234 123 123" & return
   
   click text area 1 of scroll area 4 of splitter group 1 of window "Messages"
   keystroke "hi, have new images!"
   
   repeat with theItem in theImagesPosixList
       set the clipboard to theItem
       click menu item "Paste" of menu 1 of menu bar item "Edit" of menu bar 1
       delay 1
   end repeat
   
end tell

To send message, you can add before the end tell this:

Applescript:

keystroke return

Last edited by KniazidisR (2019-05-20 01:42:04 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)