Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How can I send an email using applescript from numbers. HELP PLEASE!

I am trying to see if anyone would be able to help!


I am totally new to Applescript and was wondering if anyone would be able to help me write a script to do the following:


Write an email using the below table in Numbers, using the emails given in column B (column A is just for the persons reference) , using the email subject in column C and the actual email body from column D.


Is this possible and is there a way that I could either have some kind of desktop shortcut button or a button within a specific Numbers document?


PLEASE HELP!

MacBook Air 13″, macOS 11.0

Posted on Jun 10, 2021 11:57 PM

Reply
Question marked as Best reply

Posted on Jun 12, 2021 10:37 PM

This should get you started.


Set up your Numbers document to look like this:




The first table has one column. The first row is defined as a Header Row.


The second table has a Header Row and two body cells.


Then use a script like this:


tell front document of application "Numbers"
	tell active sheet
		-- start at row 2 and end at the last row (-1)
		set theAddresses to value of cells 2 thru -1 of column "A" of table "Addresses"
		set theSubject to value of cell "A2" of table "Content"
		set theContent to value of cell "B2" of table "Content"
	end tell
end tell

tell application "Mail"
	--create new message with subject and content
	set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent}
	-- add the To: addresses to the new message
	tell newMessage
		repeat with anAddress in theAddresses
			make new to recipient at end of every to recipient with properties {address:anAddress}
		end repeat
	end tell
end tell



Copy-paste into Script Editor (in Applications > Utilities) and with the Numbers document open to that sheet click the <run> button in Script Editor.


You cannot place a button within a specific Numbers document.


But if you use the script often then you can place it in your menu following these instructions.


A script can also be attached to a keyboard shortcut by placing it in an Automator Service (Quick Action) and going to System Preferences > Keyboard > Shortcuts > Services. You can find many explanations on-line how to do this, including this one.


SG


Similar questions

4 replies
Question marked as Best reply

Jun 12, 2021 10:37 PM in response to DMLaMiranda1990

This should get you started.


Set up your Numbers document to look like this:




The first table has one column. The first row is defined as a Header Row.


The second table has a Header Row and two body cells.


Then use a script like this:


tell front document of application "Numbers"
	tell active sheet
		-- start at row 2 and end at the last row (-1)
		set theAddresses to value of cells 2 thru -1 of column "A" of table "Addresses"
		set theSubject to value of cell "A2" of table "Content"
		set theContent to value of cell "B2" of table "Content"
	end tell
end tell

tell application "Mail"
	--create new message with subject and content
	set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent}
	-- add the To: addresses to the new message
	tell newMessage
		repeat with anAddress in theAddresses
			make new to recipient at end of every to recipient with properties {address:anAddress}
		end repeat
	end tell
end tell



Copy-paste into Script Editor (in Applications > Utilities) and with the Numbers document open to that sheet click the <run> button in Script Editor.


You cannot place a button within a specific Numbers document.


But if you use the script often then you can place it in your menu following these instructions.


A script can also be attached to a keyboard shortcut by placing it in an Automator Service (Quick Action) and going to System Preferences > Keyboard > Shortcuts > Services. You can find many explanations on-line how to do this, including this one.


SG


Jun 11, 2021 10:08 AM in response to DMLaMiranda1990

This is pretty easy to do via an AppleScript, but the devils are in the details :)


The biggest question is what happens when a cell is empty?


If the email address cell is empty, does that stop the script (i.e. end at the first missing email?

What should the subject be if the Subject cell is empty?

What should the message body be if the Message cell is empty?


Your screenshot shows numerous rows where the subject and/or message cells are empty, and it's not clear what action to take with these rows.

How can I send an email using applescript from numbers. HELP PLEASE!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.