Imessaging to a list from a csv file

I want to a make a macOS or IOS shortcut to read from csv file having names, message and send imessages after delay of 5 minutes. Honestly, I have never used shortcuts. In fact I don’t even know coding. However, by reading here and there, watching youtube videos I created a shortcut at Shortcuts.

The issue is that although the shortcut sends the imessage but it sends all messages to all persons. I mean I want to send message A to person A and message B to person B however, this shortcut sends message A and message B to person A and also to person B.

I tried show result; It all looks normal. In send message also I see that message A goes to person A and message B to person B but in reality all the messages go to all.

If you can advise some other better way than kindly advise that. I tried apple script but I couldn’t as I’m not a developer.
@sylumer please help

1 Like

Welcome to the forum, but please refrain from @ mentioning people unless there is some relevance for them to the discussion. There are many people on this forum who could help you - there is no need to explicitly call me out directly for assistance. You may just need to be patient while people find the time to look at your post, and the advantage is you get potentially lots of different insights and approaches. But you do need to give people time to do so.


I have taken a look at your shortcut and I think the flow for it looks like this:

Which I think when you take out all the redundant elements in effect resolves to this.

Now, to my eye there is nothing obvious from that as to why all message content would go to all recipients. It seems to split out the data and reference the data appropriately as part of the repeat loop and there is nothing processing the result of the loop (which is often the sort of thing that catches people out).

One thing that does strike me as odd is the regular expression replacement action. It seems to suggest that you have a double quote delimiter for each line of your CSV. What would be the benefit of delimiting the whole line when a newline is used as a separator, bearing in mind that CSV files do not supporting unencoded new lines as data because it is the record separator…

Normally in a CSV you would either have no delimiters, or your delimiters would be around each item separated by a comma. Each line is a record with fields separated by commas, and any field that could contain a comma (i.e. text content) would be delimited by double quotes.

e.g.

"Fruit","Apple",5
"Vegetable","Carrot",9
"Fruit","Orange",6

You haven’t actually given us a view of your data. Obviously you don’t want to be sharing people’s numbers or your actually messages, but a sanitised version would have allowed us to see what your data is structured like and how it matched to your shortcut’s algorithm.

Based on the shortcut, I believe your data file would look something like this:

"07110000001,message one"
"07220000002,message two"
"07330000003,message three"
"07440000004,message four"

Unless I have missed something in your shortcut, I expect it is going to be something about your data that is tripping up the shortcut, but I can’t put my finger on what it would be.

Let’s put that on hold and start from a point where the data might be something like this:

"07110000001","message one, 1"
"07220000002","message two, 2"
"07330000003, 07550000005","message three and five, 3 & 5"
"four@somemail.com","message four, 4"

These could all be valid recipients for iMessages I believe, including multiple recipients for one message and the use of an e-mail address for one too. Note both recipient in the first part of the CSV and the message in the second part of the CSV could contain commas:

Recipient (Separator) Message
"07110000001" , "message one, 1"
"07220000002" , "message two, 2"
"07330000003, 07550000005" , "message three and five, 3 & 5"
"four@somemail.com" , "message four, 4"

Here is a shortcut that I *think* does the sort of thing you want in processing a file like the one above.

The shortcut includes a number of settings you can modify as you see fit when you test. Here is the comment from the top of the shortcut that describes the options in the Dictionary action beneath it.

The Dictionary that follows holds the settings for this sample shortcut
~~~

WaitFor = number of seconds to wait before sending first message. For 5 minutes, this would therefore be set to 300.

TellMe = when set to True, the shortcut will give you a notification ahead of sending if you wanted to cancel the shortcut.

Warning = the number of seconds before sending the first message the TellMe notification will be generated

Debug = when set to True, you will get shown what is being sent to whom, and then get to see it in the Messages app with the option to send or cancel; when set to False, the messages will all be sent without any user interaction.

DebugSend = when Debug is set to True, setting this to True and will also show the message in the Messages app with the option to send or cancel for each message

  • In effect I have included options for waiting (and a notification for the chance to cancel) as well as processing a selected CSV, and processing can be sending the messages, given the option to step through and just view the messages, or step through and view & send the messages.
  • The CSV used should (closely) match the format set out above.
  • I have used a dictionary and array approach for processing each line of the CSV file just to make the parsing of the commas and and whitespace beside them (though there is none in my example file above) easier. If it was known not to have any whitespace, then splitting by "," and trimming the line’s leading and trailing " would have been an equally easy option to adopt. Hopefully, you have already looked at dictionaries in shortcuts and this will make sense - if not, do take a look before trying to understand what the shortcut is doing.

Hopefully, that shortcut and the example CSV file content is enough to give you a solid starting point to poke around at if not a fully viable solution. I have completed a number of tests with it, but nothing I would consider rigorous - I have already spent quite a while trying to figure out what might be wrong and rebuilding it as something that I think would be more robust and I have lots of other things to do this evening.

Please do review it and test it thoroughly before you consider putting anything from the shortcut into use.

1 Like

Thank you for your help. I’ll remember your instructions.

I’ve uploaded the image of csv I’m using. The code is rightly selecting the file. I can see warnings too. However, I’m getting blanks recipients and messages in text. I’ve uploaded its screenshot also.

I tried my best to understand the code. But I can’t understand/fix it.

I thank you again for helping me.


![ImessagingShortcutError|666x500](upload://ecvfKgfc9HulJCiU4Rdh66H

G4JN.jpeg)

  1. Are you posting people’s real private phone numbers and names on a public forum? If so, you probably want to delete your post above and repost with appropriately sanitised data. In addition posting data in a code block would be preferable as what you posted seems to be from Numbers which shows only data from a CSV and not the real content of the CSV = which as you will note below could be your problem.
  2. Your post looks to have at least one broken image embed link in it. We may be missing additional data you were trying to show us.
  3. If you are using my shortcut as is, please ensure your actual CSV format matches the format of the example I used. Looking at your Show Text action you have entries in your JSON array that are missing double quotes, so I imagine the shortcut would struggle to reconcile that and so would likely produce an error.
  4. Do try and take the time to understand what is going on step by step. This will be your best chance of understanding what is going on. Read the documentation, test it, look it up online, etc. You may not be able to understand the shortcut right now, but everyone who knows how to use Shortcuts starts from that same place. Did you realise that the only difference between a developer and a non-developer in any language/app/etc, is that one of them has spent the time and put in the effort to learn and the other one hasn’t (yet).