title: Dummy: MACOS, send message to recipient
body: <p>I would like to send messages (SMS or iMessage) to different recipients. My body text is different for each recipient.</p>
  <p>Using example provide <a href="https://github.com/rdyson/bulk-macos-messages" rel="nofollow noreferrer">Source</a></p>
  <p>I have created one Macos script send.scpt</p>
  <code>
  <pre><code>    -- Get environment variables message and recipients
  set message to system attribute &quot;message&quot; 
  set recipients to system attribute &quot;recipients&quot;
  
  -- Print the list of recipients to the console
  log recipients
  
  tell application &quot;Messages&quot;
      -- Get the Messages service of type iMessage
      set targetService to 1st service whose service type = iMessage
  
      -- For each 'recipient' in the list of recipients, set the 'buddy' item
      -- then send the text in the 'message' variable to that recipient  
      repeat with recipient in words of recipients
          set recipient to buddy recipient of targetService
              send message to recipient
      delay 1
      end repeat
      
  
  end tell
  </code></pre>
  <code>
  The shell script is send.sh
  <pre> #!/bin/bash
  
  # Watch the file named sms.txt; add a custom directory (like Dropbox or Files) to reference a file outside of the current directory.
  directory=.
  tail -F ${directory}/sms.txt | while read line; do
  
    # If the file has a line containing 'recipients'
    if echo &quot;$line&quot; | grep -q 'recipients'; then
      # Set sms.txt 'recipients' and 'message' as env vars,  Run AppleScript 
      source ${directory}/sms.txt
      echo &quot;sending&quot;
      message=$message recipients=$recipients osascript send.scpt   fi
  
  
  done
  </code></pre>
  <p>I have added examples in file sms.txt as</p>
  <pre>recipients=&quot;0123456789&quot; message=&quot;Testing&quot;
  recipients=&quot;9123456780&quot; message=&quot;TOTO&quot;
  </code></pre>
  <p>The script sends the message to each recipient but using only the message from the last line. I can't understand why. Someone can explain which command from the shell takes into consideration the last line.</p>
  <p>Thanks for your help</p>
  <p>Philippe</p>