Skip to content

Instantly share code, notes, and snippets.

@earltedly
Created January 4, 2021 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earltedly/78b60f81c2c6aac3b4a6c7ac46b50456 to your computer and use it in GitHub Desktop.
Save earltedly/78b60f81c2c6aac3b4a6c7ac46b50456 to your computer and use it in GitHub Desktop.
/*{
"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