So I'm trying to write an apple script that sends emails to a selected block of information in numbers.
Numbers is formatted like this:
Here is my apple script:
on run {input, parameters}
if the class of input is not string then set input to input as string
set currentRow to my theSplit(input, "*")
set row to 1
repeat while row <= (count of currentRow)
set fullInput to {}
set fullInput to my theSplit(item row of currentRow, " ")
set row to row + 1
set theName to ""
if item 2 of fullInput is "" then
set theName to item 1 of fullInput
else
set theName to item 2 of fullInput
end if
set theContent to "Hello " & theName & ", Email Body"
tell application "Mail"
set thisMessage to make new outgoing message with properties {subject:"HTML5 Game Sponsorships", content:theContent}
tell thisMessage
make new to recipient with properties {address:(item 3 of fullInput)}
set visible to true
end tell
end tell
end repeat
end run
on theSplit(theString, theDelimiter) set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to theDelimiter set theArray to every text item of theString set AppleScript's text item delimiters to oldDelimiters return theArray end theSplit
The script creates the emails properly, formats the information correctly. But the problems lies when rows in numbers do not contain a name. The script is suppose to say Hello 'Company Name', when a name is blank.
It does this, but for some reason it writes:
Hello 'Company Name',
It's not supposed to be on the next line. I assume this is because there is some invisible character that represents a line break that I need to remove somehow. The weird thing is that it only does this when it's the second time it needs to use a company name, it gets the first time right.
Well I hope that made sense, any help is greatly appreciated.
