Integrated eMail Support

Using Omni Automation you can construct and manipulate outline documents, apply styles and import data from a variety of sources. And with integrated scripting support for creating and sending email, it becomes easy to automate the sending of content and documents. The following documentation demonstrate how to access and use this ability, beginning with a set of parameters for generating an email.

Constructor

Omni Automation in OmniGraffle supports an Email class, design for creating and sending electronic mail messages. To instantiate an instance of this class, it is preceded by the new constructor.

Instance Properties

As with most scriptable objects, an instance of the Email class has properties that define its design and usage. Here is the list of properties for this class:

Instance Functions

The Email class contains a single command generate() for processing instances of the class.

var email = new Email() email.subject = "Omni Automation" email.body = "Greetings!\n\nHere are my suggestions regarding Omni Automation:" email.receiver = "support@omnigroup.com" email.generate()
omnifocus://localhost/omnijs-run?script=try%7Bvar%20email%20%3D%20new%20Email%28%29%0Aemail%2Esubject%20%3D%20%22Omni%20Automation%22%0Aemail%2Ebody%20%3D%20%22Greetings%21%5Cn%5CnHere%20are%20my%20suggestions%20regarding%20Omni%20Automation%3A%22%0Aemail%2Ereceiver%20%3D%20%22support%40omnigroup%2Ecom%22%0Aemail%2Egenerate%28%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

Here’s a plug-in that creates a new outgoing mail message containing the contents of the note of the selected task:

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.note-to-email", "version": "1.0", "description": "This action will add the note text of the selected task to a new outgoing mail message.", "label": "Note to Email", "shortLabel": "Note to Email" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags, allObjects var task = selection.tasks[0] var taskTitle = task.name var noteText = task.note if(noteText === ""){ var alertMsg = "The note of the selected task contains no text." new Alert("Missing Data", alertMsg).show() } else { var email = new Email() email.subject = "Note of task “" + taskTitle + "”" email.body = noteText email.receiver = "" email.generate() } }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags, allObjects return (selection.tasks.length === 1) }; return action; })();

Here’s an example action plug-in that creates a new mail message containing a OmniFocus URL for generating a copy of the selected task:

Including Attachments

The following are examples of creating and sending mail messages whose contents are derived from the current document.

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.send-omnifocus-backup", "version": "1.0", "description": "This action will create a new email message containing a backup copy of the OmniFocus database.", "label": "Send Backup", "shortLabel": "Send Backup" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ fileTypeID = "com.omnigroup.omnifocus.filetype.ofocus-backup" baseName = "OF Backup" wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ var email = new Email() email.subject = "Export of " + baseName email.body = "Here is a backup of my OmniFocus database:\n\n" email.fileWrappers = [wrapper] email.generate() }) wrapperPromise.catch(function(err){ console.error(err.message) }) }); action.validate = function(selection, sender){ return true }; return action; })();

DISCLAIMER