×

Plug-In: Note to File

This action will save the note text of the selected task to a file. On macOS, the option to open the created file will be presented after the export has completed.

Return to: OmniFocus Plug-In Collection

Note to File
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.note-to-file", "version": "1.0", "description": "This action will save the note text of the selected task to a file.", "label": "Note to File", "shortLabel": "Note to File" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags, allObjects var task = selection.tasks[0] var textToWrite = task.note if(textToWrite === ""){ var alertMsg = "The note of the selected task contains no text." new Alert("Missing Data", alertMsg).show() } else { var textDataObj = Data.fromString(textToWrite) var textFileName = task.name + " note.txt" var wrapper = FileWrapper.withContents(textFileName, textDataObj) var filesaver = new FileSaver() var fileSaverPromise = filesaver.show(wrapper) fileSaverPromise.then(function(urlObj){ console.log(urlObj.string) if(Device.current.mac){ var alertTitle = "File Created" var alertMsg = "Open the file?" var alert = new Alert(alertTitle, alertMsg) alert.addOption("Open") alert.addOption("Skip") alert.show(function(result){ if (result == 0){urlObj.open()} }) } }) fileSaverPromise.catch(function(err){ console.log(err.message) }) } }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags, allObjects return (selection.tasks.length === 1) }; return action; })();