Drafts Action Directory

Add to log

Posted by @tlmnlpstz, Last update about 1 month ago

Creates a new draft or appends to an existing draft with the title “# YEAR-MM-DD Log” (can be changed in the script). The Log draft is tagged with “journal” (can be changed in the script).

New lines are created from the [[draft]] with this pattern: HH:MM: [[draft]]

Install

Steps

  • script

    // tag to assign to drafts
    const logTag = "journal";
    
    // create date variable
    var dte = new Date();
    var date = dte.toISOString().slice(0,10);
    
    var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
    var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(11, 16);
    
    
    // grab text
    const currentContent = localISOTime + ": " + draft.content.trim();
    
    // query for drafts...
    var drafts = Draft.query(date, "inbox", [logTag]);
    // loop over found drafts looking for a matching list
     var d;
      for (var draft of drafts) {
       if (draft.content.startsWith("# " + date + " Log")) {
        d = draft;
       }
      }
    
    // if we didn't find the list, create it...
    
    if (!d) {
    d = Draft.create();
    d.content = "# " + date + " Log" + "\n\n";
    }
    
    // tag and update content
    d.addTag(logTag);
    d.content = d.content + "\n" + currentContent + "\n"
    d.update();

Options

  • After Success Default
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.