i like using a “waiting” tag for items, besides using a km macro, is that possible natively?
Here’s a script that I think starts to do what you want:
function TaskPaperContextScript(editor, options) {
var today = DateTime.format('today');
var outline = editor.outline;
outline.groupUndoAndChanges(function() {
editor.selection.selectedItems.forEach(function (each) {
if (!each.hasAttribute('data-waiting')) {
each.setAttribute('data-waiting', today);
}
});
});
}
Application("TaskPaper").documents[0].evaluate({
script: TaskPaperContextScript.toString()
})
i was kind of hoping that when adding the waiting tag it would auto insert the date like marking a task as done.
Can you describe the exact sequence of events that you are looking for. It should be that when you run this script @waiting(2016-03-02)
is inserted. Just like when you tag an item done @done(2016-03-02)
.
Would it be possible to add a toggle function, so the same keyboard shortcut can either add the waiting tag if it doesn’t exist, or remove the waiting tag if it already does?
This script is a bit more complicated, but it should work exactly like the Toggle Done command, except with a different tag… (I think!)
function TaskPaperContextScript(editor, options) {
function setAttribute(editor, items, name, value) {
var outline = editor.outline;
var selection = editor.selection;
outline.groupUndoAndChanges(function() {
items.forEach(function (each) {
each.setAttribute(name, value);
});
});
editor.moveSelectionToItems(selection);
}
function toggleAttribute(editor, items, name, value) {
items.forEach(function (each) {
if (each.hasAttribute(name)) {
value = null; // If any item has the attribute, then remove it from all.
}
});
setAttribute(editor, items, name, value);
}
toggleAttribute(editor, editor.selection.selectedItems, 'data-waiting', DateTime.format('today'));
}
Application("TaskPaper").documents[0].evaluate({
script: TaskPaperContextScript.toString()
});
Just tested it and it does — brilliant! Thank you so much.
nice!
any thoughts on removing all tags when a task is marked as done?
I don’t think I’d like to do that for the default “Done” command. But (as often) it’s easy to do in a script. In fact the data-waiting
script is a great starting point, you’d only need to make a few changes. But I want you to try this one . Here’s what you’d have to do:
-
Change
data-waiting
todata-done
since you are toggling the @done tag instead of @waiting tag. -
In the case when @done is being added added (
value != null
) also remove all the other tags. -
Use
each.attributeNames
to get all item attribute names. (each is anItem
instance) -
You only want to remove the attributes that represent @tags. (there are other attributes associated with items such as
indent
). You can tell if an attribute name is associated with a tag by checking to see if the name starts withdata-
. So for eacheach.attributeNames
that starts withdata-
then calleach.removeAttribute
. -
The scripting API is documented at http://guide.taskpaper.com/scripting_api.html. If it doesn’t go smoothly please post any questions here!
challenge accepted! i think i’ll appreciate this help much more!
challenge still sccepted, I’ve just been on a crash course learning Python for my 3-D modeling program