I’m trying to make an automation which duplicate the current task(s), pre-pends "Follow up on: " to the duplicated task, removes all current tags and sets the main tag to follow up and then completes the original task.
However I have no knowledge of javascript😢,
but I do have two pieces which do what I want 😃,
but I don’t know how to combine them.😢
Any help would be appreciated.
/*{
"author": "John",
"targets": ["omnifocus"],
"type": "action",
"identifier": "com.John.omnifocus.combined",
"version": "1.0",
"description": "Remove all tags and tag with follow up.",
"label": "combined",
"mediumLabel": "combined",
"paletteLabel": "combined",
}*/
(() => {
let action = new PlugIn.Action(function(selection) {
let duplicatedTasks = new Array()
selection.tasks.forEach(function(task){
insertionLocation = task.containingProject
if(insertionLocation === null){insertionLocation = inbox.ending}
dupTasks = duplicateTasks([task], insertionLocation)
dupTasks[0].name = "Follow up on: " + task.name;
duplicatedTasks.push(dupTasks[0].id.primaryKey);
task.markComplete();
});
idStr = duplicatedTasks.join(",")
URL.fromString("omnifocus:///task/" + idStr).open()
});
action.validate = function(selection){
return (selection.tasks.length >= 1)
};
return action;
})();
(() => Object.assign(
new PlugIn.Action(selection => {
// USER DATA -----------------------------------------
const tagName = 'Follow up';
// OMNI JS CODE ---------------------------------------
const omniJSContext = () => {
// main :: IO ()
const main = () => {
return selection.tasks.map(x => (
x.removeTags(x.tags),
addTag(
tagFoundOrCreated(tagName)
)(x)
))
};
// FUNCTIONS --
// OmniFocus OmniJS --------------------------------------------
// addTag :: Tag Object -> OFItem -> OFItem
const addTag = oTag => item => {
item.addTag(oTag)
return item
}
// tagFoundOrCreated :: Tag Name -> Tag Object
const tagFoundOrCreated = strTag =>
tagNamed(strTag) || new Tag(strTag)
// MAIN -----------------------------------------
return main()
};
return omniJSContext()
}), {
validate: selection => selection.tasks.length > 0
}
))();