/*{
	"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;
})();