Add timestamp to done tasks

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

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).

1 Like

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()
});
1 Like

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

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

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!)

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

1 Like

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:

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

http://support.foldingtext.com/t/how-do-i-run-install-a-script/1740?u=jessegrosjean

@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

2 Likes

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

1 Like

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!

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.

the CMD - D worked!

Thank you Jesse! :slight_smile:

I know this is an old thread, but some of the links from it are broken, so I was having a bit of trouble. I did get it to work with KeyboardMaestro, but that has to be with a keyboard shortcut. Normally I am all about keyboard over mouse, but I am somehow used to just clicking the dash at the beginning of each task to mark it as done. Is there any way to use this script to add the timestamp when I do that? Perhaps this is not possible, but seemed worth asking since the FAQ @jessegrosjean posted has gone stale (not even in the Internet Archive!).

Thanks,
JC

Sorry I don’t think you can do it without the keyboard shortcut method.

And the FAQ that I posted above was for the wrong app anyway (it was a link to FoldingText’s guide, which I sold to another developer). Anyway the current link for installing scripts would be:

https://www.taskpaper.com/guide/using-taskpaper/using-scripts.html

Thank you for clarifying that. I’ll try to require my habit then :slight_smile:

1 Like

Is there any way to disable clicking the dash to mark as done? I’m having a hard time switching my habit to using cmd-D and I think it would help if clicking no longer did anything.

Sorry I don’t think there is.