×

Plug-In: Just For Today

This plug-in uses the fetch() function of the URL class (LINK) to retrieve the contents of the Just For Today website (https://www.jftna.org/jft/) and then sets the note of the inbox task “JFT” to the cleaned content.

Just For Today
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.just-for-today", "version": "1.0", "description": "Retrieves the contents of the Just For Today website (http://www.jftna.org/jft/) and sets the note of the inbox task “JFT” to the cleaned content.", "label": "Just For Today", "shortLabel": "Just For Today", "paletteLabel": "JFT", "image": "doc.append" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // Just For Today website var url = URL.fromString("http://www.jftna.org/jft/") // retrieve contents of webpage url.fetch(function(data){ // remove HTML tags from text content var strNoTags = data.toString().replace(/(<([^>]+)>)/gi, "") // trim whitespace from paragraphs var paragraphs = strNoTags.split("\n") paragraphs = paragraphs.map(item => {return item.trim()}) // change triple-spaces to double-spaces var str = paragraphs.join("\n") while(str.indexOf("\n\n\n") >= 0) { str = str.replace(/\n\n\n/g, "\n\n") } // replace fixed-space tag with space str = str.replace(/&nbsp;/gi, " ") // locate task, create task if needed var task = inbox.byName("JFT") || new Task("JFT") // set the note to the retrieved text task.note = str // show the task URL.fromString("omnifocus://task/" + task.id.primaryKey).open() }, function(err){ new Alert(err.name, err.message).show() }) }); action.validate = function(selection, sender){return true}; return action; })();