Created
January 4, 2021 12:10
-
-
Save earltedly/78b60f81c2c6aac3b4a6c7ac46b50456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*{ | |
"author": "Ted Bradley", | |
"targets": ["omnifocus"], | |
"type": "action", | |
"identifier": "com.tedbradley.Move to DT", | |
"version": "0.1", | |
"description": "Moves the current task to the DevonThink global inbox", | |
"label": "Move to DT", | |
"mediumLabel": "Move to DevonThink", | |
"paletteLabel": "Move to DT", | |
}*/ | |
(() => { | |
var action = new PlugIn.Action(function(selection) { | |
task = selection.tasks[0] | |
var urlString = "x-devonthink://" | |
var linkURLStr = "omnifocus:///task/" + task.id.primaryKey | |
var bookmarkUrl = "" | |
var note = (selection.projects.length === 1 ? selection.projects[0].task.note : selection.tasks[0].note); | |
if (note && note.includes("://")) { | |
var noteUrl = note.match(/[^<\s][^\s]+\/\/[^\s>]+/)[0] | |
if (noteUrl.length == note.length) { | |
urlString += "createBookmark" | |
bookmarkUrl = noteUrl | |
} else { | |
urlString += "createMarkdown" | |
} | |
} | |
urlString += "?title=" | |
urlString += encodeURIComponent(task.name) | |
urlString += "&text=" | |
urlString += encodeURIComponent(note) | |
urlString += "&referrer=" | |
urlString += encodeURIComponent(linkURLStr) | |
if (bookmarkUrl.length > 0) { | |
urlString += "&location=" | |
urlString += encodeURIComponent(bookmarkUrl) | |
} | |
var url = URL.fromString(urlString) | |
console.info(url) | |
if (url) { | |
url.open() | |
task.markComplete() | |
} else { | |
console.error("ERROR: \"" + urlString + "\" is not a valid URL.") | |
} | |
}); | |
action.validate = function(selection, sender){ | |
return (selection.tasks.length === 1 && selection.tasks[0].hasChildren === false) | |
}; | |
return action; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment