JonC
February 16, 2021, 8:11am
1
Is anyone able to help with the use adding a tag?
The following works, and returns the tag:
var tag = flattenedTags.byName(“Response📨”);
console.log(tag)
But if I use the following line (amended Plugin of of-complete-await-reply.omnijs)
dupTasks[0].addTag(tagNamed(“Response📨”));
with the not found error of ‘Error: Function Task.addTag argument “tag” at index 0 requires a non-null value’
I’ve tried adding spaces, changed “” to ‘’ but I can not get it to work, a top level tag of “Test” does work.
Any ideas?
Thank you
draft8
February 16, 2021, 9:10am
2
Perhaps the use of tagNamed
in the preamble to the plugin snippet assumes a slightly different context ?
.tagNamed
is either a method of a Tag object, which lets you find its child tags by their name, or a method of the Database object, which lets you find a tag at the top level of nesting.
As you have already got a reference to the tag you want with:
const responseTag = flattenedTags.byName("Response📨");
You should be able to apply the .addTag
method to that reference directly:
(() => {
"use strict";
const responseTag = flattenedTags.byName("Response📨");
// etc etc ... defining dupTasks and dupTasks[0] somewhere ...
// e.g. dupTasks = flattenedTasks; ...
dupTasks[0].addTag(responseTag);
})();
1 Like
draft8
February 16, 2021, 10:28am
3
If you weren’t sure whether a tag existed or not, you could write something like this:
(() => {
"use strict";
// main :: IO ()
const main = () =>
tagAddedByName("Response📨")(
document.windows[0].selection.tasks[0]
);
// -------------------- OMNIFOCUS --------------------
// tagsAddedByName :: String -> IO String
const tagAddedByName = tagName =>
task => {
const
tagOrNull = flattenedTags.byName(tagName),
[message, foundOrCreated] = (null !== tagOrNull) ? (
["found", tagOrNull]
) : ["created", new Tag(tagName)];
return Boolean(task) ? (
// In OmniFocus:
task.addTag(foundOrCreated),
// and in JavaScript:
`Tag: '${tagName}' ${message} and added to task: ${task.name}`
) : "No task reference supplied.";
};
// MAIN ---
// Everything defined now ... ready to evaluate.
return main();
})();
JonC
February 16, 2021, 10:29am
4
Thank you, by using this method has fixed the issue.
1 Like