Add timestamp to done tasks


#1

Hi all,

I’m sorry - I just came across TaskPaper and this looks so good! But: I’m missing one thing - I’d like to see the timestamp when I finished a task - like @done 2016-03-21 10:11. Can I achieve that somehow? Haven’t found no solution on the forums or the options page.
Thanks
Ben


#2

There’s a section in the preferences that lets you do that with the date; you might need to use Javascript to have date + time.

When you select that, the tag becomes @done(2016-03-28).


#3

I don’t know enough about Javascript to get the date/time formatted nicely, but the script below will yield a tag formatted like @done(2016-03-28 15:33:54:457) (down to the millisecond!) It will also toggle the status (so removing the “done” tag if it already exists)

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-done', DateTime.format('now'));
}

Application("TaskPaper").documents[0].evaluate({
  script: TaskPaperContextScript.toString()
});

#4

To show to the current minute you can change your script to use:

toggleAttribute(editor, editor.selection.selectedItems, 'data-done', DateTime.format('this minute'));

#5

Awesome, thanks! The full script for those who just want to copy/paste:

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-done', DateTime.format('this minute'));
}

Application("TaskPaper").documents[0].evaluate({
  script: TaskPaperContextScript.toString()
});

(I can’t remember if @jessegrosjean or @complexpoint wrote the original script for this, but credit for it goes entirely to them!)


#6

Guys, Thanks a lot!

You are really awesome!

I already told I’m new, so I hope you don’t mind my next question (isnt explained in the FAQ or the manual): what Do I do with this code above? Don’t see any inapp code/script editor or so.

Thanks again!

Ben


#7

I used Keyboard Maestro, which (among many other things) lets you link the script to a hotkey (like the default ⌘D for done tasks).

There should also be a way to save it as a Service, which you could then assign a hotkey in System Preferences. I’m not sure how to do it myself, but I believe I’ve seen someone explain it in one of the other script posts in this form. (List of the script posts is here)

Zip of the script for download:
Add Timestamp to Done Tasks.zip (1.2 KB)

Hope this helps! :whale:


#8

I’ve just added a FAQ with a some more pointers:


#9

@esotaria, I stopped keeping that page up to date and I have been working on and organizing the official “extensions” page. It should be in pinned at the top of the forums. Here is a link


#10

Thanks a lot. That’s great support here! :smile:


#11

Hello…I am definitely not a code type person, if my question seems silly, my apologies :slight_smile:

I have noticed that the date stopped being added to my @done tasks. I have the box checked in the preference pane.

I have tried checking and and unchecking the box to see if it kickstarts it, but no go.

Do I need to have a script or something installed to make it happen?

Please Advise…thanks!


#12

No you shouldn’t need a script, it should just be controlled by the “Include date when tagging task with @done” setting in preferences. A few possibilities:

  1. If you type out the done tag … i.e. manually type @done (or partially type it and use autocomplete to finish) a date is not added. Dates are only added when you do menu Tag > Done (or it’s Command-D) shortcut. Or when you add tags using the menu Tag > Tag With… (Command-T)

  2. I’ve just been testing and this all seems to be working on TaskPaper 3.7.3.

If that still doesn’t help try:

  1. Quit TaskPaper
  2. Delete TaskPaper’s preferences plist.
  3. Restart TaskPaper.

Please let me know if any of the above solve or not.


#13

the CMD - D worked!

Thank you Jesse! :slight_smile: