Action

process Drafts in INBOX

Posted by @FlohGro, Last update 28 days ago

This action can be used to quickly sort out your INBOX workspace.

The script will query your drafts from the defined workspace and ask you which of your action you want to run on the draft

BEFORE YOU RUN THIS ACTION:
1. adapt the name of your „INBOX“ workspace
2. adapt the display names and action names of the actions you want to run on your inbox drafts

Drafts is my main INBOX for everything text related. Whether its a link from a webpage i want to save or a quick thought, a task or any other note. I want to stay Inbox Zero and that’s where this action speeds the things up a lot. I just run it and if possible I can decide just with the title of the draft what needs to be done with it (e.g. push it to the todoist inbox, save the link in DEVONthink and so on). The actions i select to run on the draft will actually be executed after the „process Drafts in INBOX“ action one after the other.

created by @FlohGro, if you have any questions please ask me in Drafts Discourse forum.

Steps

  • script

    // created by @FlohGro
    
    // process drafts from INBOX
    // ----------------------------------------------------
    // START OF USER DEFINITIONS
    
    // define the name of your inbox workspace
    let inboxWorkspaceName = "INBOX";
    
    // declare "display names" (for the prompt) and "action names" (from your Actions) in an array:
    // the last pair does not need a "," after the [] brackets!s
    let actionArray = [
      ['skip', ''],
      ['✅ Todoist inbox lines', 'INBOX line’s'],
      ['🔗 Todoist URL Task', 'Draft URL Task'],
      ['🗂 Bookmark to DEVONthink', 'bookmark to DEVONthink'],
      ['⌨️ Markdown to DEVONthink', 'Markdown to DEVONthink CB'],
      ['🏷 add tags from category', 'add tag from category'],
      ['🗑 trash', 'trash']
      //   ['', ''],
      //   ['', ''],
      //   ['', ''],
    ];
    
    // END OF USER DEFINITIONS
    // ----------------------------------------------------
    
    let actionMap = new Map(actionArray);
    // - get drafts from INBOX Workspace
    let inboxWorkspace = Workspace.find(inboxWorkspaceName);
    let inboxDrafts = inboxWorkspace.query("all");
    
    // loop through every draft (show title and prompt for action on it)
    
    for (inboxDraft of inboxDrafts) {
      let actionPrompt = new Prompt();
      actionPrompt.title = "process draft"
      actionPrompt.message = "draft: " + inboxDraft.displayTitle;
    
      // add button for all elements in the actionMap
    
      actionMap.forEach(function(value, key) {
        actionPrompt.addButton(key, value);
      })
      actionPrompt.isCancellable = false;
      actionPrompt.show();
    
      let selectedAction = actionPrompt.buttonPressed;
    
      if (selectedAction == '') {
        // no action for the given name
      } else {
        let action = Action.find(selectedAction);
        app.queueAction(action, inboxDraft);
      }
    
    }

Options

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