Save all to iCloud Drive

Posted by RoyRogers, Last update 24 days ago

This will save all drafts to the Drafts folder in iCloud
- Gets file name from “safe_title - created date”:
- file name = “title - yyyy-mm-dd_hhmm”,
- so updated drafts overwrite old versions.

Steps

  • script

    // Save all to iCloud drive
    // 2020-03-07 at 11:08
    
    // Gets file name from "safe_title - created date":
    // file name = "title - yyyy-mm-dd_hhmm",
    // so updated drafts overwrite old versions.
    
    // Select all drafts (safer when moved later)
    var boxes = ["all"];
    // var boxes = ["inbox", "flagged", "archive"];
    
    // Query all of the drafts with specific tag
    // var tag = "any" // "script";
    
    for(let box of boxes) {
      console.log(box);
      let drafts = Draft.query("", box); //,[tag]);
      for(let draft of drafts) {
        let title = draft.processTemplate("[[safe_title]]");
        let created = draft.processTemplate("[[created|%Y-%m-%d_%H%M]]");
        let content=draft.processTemplate("[[draft]]").trim();
        let tags = draft.processTemplate("[[tags]]");
        if (tags != '') {
          content += '\n\n#' + tags.replace(/,/g, ' #');
        }
        let path = `/Drafts_${box}/${title} - ${created}.md`;
        let fmLocal = FileManager.create(false);
        let success = fmLocal.write(path, content);
      }
    }
    
    

Options

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