Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kaustavha
Last active March 1, 2016 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaustavha/25388d53d39b55af511d to your computer and use it in GitHub Desktop.
Save kaustavha/25388d53d39b55af511d to your computer and use it in GitHub Desktop.
Using node to generate applescript for sending emails

This is an example of using nodejs to generate applescript for sending out emails.

node example.js

Will output the applescript to console. On a mac with microsoft outlook configured and applescript one can create an applescript file and run it. e.g.

osascript out.osascript

This will send an email that looks like email.txt This script is handy if you have a list of emails thats somewhat long

Hi,
First line
Second line
Thank you,
Kaustav
var emails = ['hi@kaustav.me'];
function generateApplescript(content, subject, acc, cc) {
var appleScript = 'tell application "Microsoft Outlook"';
appleScript += '\n set theContent to ' + content;
appleScript += '\n set newMessage to make new outgoing message with properties {subject: "'+subject+'", content:theContent} ';
appleScript += '\n make new to recipient at newMessage with properties {email address: {address:"'+acc+'"}}';
if (cc) {
appleScript += '\n make new cc recipient at newMessage with properties {email address: {address:"'+cc+'"}}';
}
appleScript += '\n send message id (id of newMessage)';
appleScript += '\nend tell';
// console.log(appleScript);
return appleScript;
}
function createScript(emails) {
emails.forEach(function(email) {
if (email) {
var content = '"<p> Hi, </p>';
function cc(str) {
content += str + '<br>';
}
content += '<p>'
cc("First line");
cc("Second line");
content += '</p><p>' // Line break at end of message
cc("Thank you,");
cc("Kaustav");
content += '</p>"';
console.log(generateApplescript(content, 'subject', email));
}
});
}
createScript(emails);
tell application "Microsoft Outlook"
set theContent to "<p> Hi, </p><p>First line<br>Second line<br></p><p>Thank you,<br>Kaustav<br></p>"
set newMessage to make new outgoing message with properties {subject: "subject", content:theContent}
make new to recipient at newMessage with properties {email address: {address:"hi@kaustav.me"}}
send message id (id of newMessage)
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment