Append Hour Log

Posted by RAK, Last update 17 days ago

Steps

  • script

    /*
      find draft for today, if not exists, create with tag
    */
    
    // Modify String to set format of you title
    var today       = new Date();
    var todayString = strftime(today.getTime() , "%Y%m%d, %a");
    var timeString  = strftime(today.getTime() , "%H:%M: ");
    
    // EDIT TAG
    // tag to assign to list drafts
    const listTag = "workhours";
    
    // grab text
    const newEntry = draft.content.trim();
    
    // Search for existing draft for today
    var whDrafts = Draft.query(todayString, "inbox", [ listTag ]);
    
    if (whDrafts.length == 0) {
    // no draft for today existing, create one
      var newDay = Draft.create();
      newDay.addTag(listTag);
      newDay.content = "# " + todayString + "\n" + timeString + newEntry;
      newDay.update();
      editor.load(newDay);
      editor.focus();
    } else {
      // find draft with todays title. if more than one is existing update all
      for (var i=0; i<whDrafts.length; i++) {
        var t = whDrafts[i].title;
        if (t == todayString) {
          var existingEntries = "\n" + whDrafts[i].content
            .split("\n")
            .slice(1)
            .join("\n");
          whDrafts[i].content = "# " + t + "\n" + timeString +
            newEntry + 
            existingEntries;
          whDrafts[i].update();
          editor.load(whDrafts[i]);
          editor.focus();
        }
      }
    }
    
    

Options

  • After Success Archive
    Notification Info
    Log Level Info
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.