Skip to main content
Question

Apple Script Help


Forum|alt.badge.img+14
  • Valued Contributor
  • 375 replies

Hello All!

I am looking for some guidance to send a bulk email from a CSV using an Apple Script. I exported a CSV that has a column of oweners and then the value is john doe doe@company.com. My goal is to take this list and send emails to each user with a standard reminder. I have been using this script, but cannot figure our for the life fo me how to adjust the values to read just doe@company.com

-- select the file
-- change this to a direct path if you prefer
set theFile to (choose file with prompt "Select the CSV file")

-- read the file contents:
set f to read theFile

-- break the file into paragraphs (c.f. rows)
repeat with row in (paragraphs of f)
  -- parse the row into comma-delimited fields
  set fields to parseCSV(row as text)
  -- now you have your data:
  set recipientAddress to item 1 of fields
  set theSubject to item 2 of fields
  set theContent to item 3 of fields
  set recipientName to item 4 of fields

  -- presumably you want to do something more with this data?
  tell application "Mail"
  set NewMail to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
  set message signature of NewMail to signature "OG"

  tell NewMail
  make new to recipient with properties {name:recipientName, address:recipientAddress}


  send
  end tell
  end tell
end repeat

on parseCSV(theText)
  set {od, my text item delimiters} to {my text item delimiters, ","}
  set parsedText to text items of theText
  set my text item delimiters to od
  return parsedText
end parseCSV

Thanks for any help!
Jared

5 replies

Forum|alt.badge.img+14
  • Author
  • Valued Contributor
  • 375 replies
  • January 17, 2018

bump


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • January 17, 2018

Can you give a quick example of how the csv is formatted? That might help someone in figuring out your issue.


Forum|alt.badge.img+26
  • Valued Contributor
  • 907 replies
  • January 17, 2018

Throwing out a random idea...since you can combine AppleScript and bash scripts together using the osacript command within bash, consider using awk or sed or whatnot to "finesse" a problematic line of text for you and then bring that final result back into AppleScript.

Not actually sure if that would work or what the syntax would be, but in thinking mode right now with this post.


Forum|alt.badge.img+14
  • Author
  • Valued Contributor
  • 375 replies
  • January 18, 2018

Thanks for reaching out @mm2270 and @blackholemac. I am new to Apple Scripting so I am trying to edit any sort of script to get something working
. Here is an example of the CSV:


Forum|alt.badge.img+4
  • Contributor
  • 14 replies
  • January 18, 2018

Try this:

on parseMail(theText) set {od, text item delimiters} to {text item delimiters, "<"} set parsedText to text items of theText set text item delimiters to od return parsedText end parseMail set addr to parseMail("John Doe john@doe.com")

Removal of trailing spaces and trailing '>' is left as an exercise for the student.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings