Save changed to Dropbox

Posted by RoyRogers, Last update about 3 years ago

This will save all modified drafts to /Drafts/ folders in Dropbox using the title line as the file name, and in sub folders for inbox, tagged and archive.

Uses a hidden timestamp file to check against modified since last run. If this file is missing, all drafts will be copied.

Note: Existing files with same name will be overwritten!
Note: Trashed drafts will not be trashes from Dropbox!


  • script

    // Save all Drafts to iCloud
    // grab all of the drafts with specific tag
    // var tag = "any" // "script";
    var boxes = ["inbox", "flagged", "archive"];
    const now = new Date();
    const ts = now.toString("yyyyMMddhhmmss");
    var db = Dropbox.create();
    var ts_file = '/Drafts/.time_stamp.txt'
    var lastime = Number(;
    if (isNaN(lastime)) {
      lastime = 0};
    var success = db.write(ts_file, ts, "overwrite", true);
    for(const box of boxes) {
      var drafts = Draft.query("", box); //,[tag]);
      for(const draft of drafts) {
        var mod = Number(draft.modifiedAt.toString("yyyyMMddhhmmss"));
        if (mod < lastime) {
        var title = draft.processTemplate("[[safe_title]]");
        var content=draft.processTemplate("[[draft]]").trim();
        var tags = draft.processTemplate("[[tags]]");
        if (tags != '') {
          content += '\n\n    #' + tags.replace(/,/g, ' #');
        var path = "/Drafts/"+box+"/"+title+".txt";
        var db = Dropbox.create();
        var success = db.write(path, content, "overwrite", true);
      }; // end for drafts
    }; // end for of boxes


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