Drafts Action Directory

Add to list

Posted by agiletortoise, Last update 5 months ago

Append to running lists in Drafts.

See it in action

Prompt user to select a category, and append the text of the draft to a list in a draft tagged “list”, with a header for the category. If the list for the category does not already exist, it will be created.

Intended as an example of how to maintain lists of ideas, movies you want to remember, etc. Category array and tag to use to identify lists at the top can be altered to meet needs.

Example Use

  • Type “Godfather” in a draft
  • Tap “Add to list”, select “Movies” as category.
  • Assuming this is the first time to select “Movies”, a draft with the tag “list” will be created, with the following text:
## Movies

- [ ] Godfather
  • Type “Jaws” n a new draft, tap “Add to list”, select “Movies”, the existing draft will be updated to:
## Movies

- [ ] Godfather
- [ ] Jaws

These list can then be found by filtering the draft list by the tag “list”. Create a Workspace for “lists” with a tag filter to easily access lists.

Modifying

There are two lines of JavaScript near the top of the script that can be edited to change the available categories and the tag used to mark lists.

Install

Steps

  • script

    /*
      Ask for a category, and append to a tagged list for that category
    */
    
    // EDIT THIS
    // setup categories available
    const categories = ["Movies", "TV Shows", "Blog Ideas"];
    
    // EDIT TAG
    // tag to assign to list drafts
    const listTag = "lists";
    
    // grab text
    const currentContent = draft.content.trim();
    
    // prompt to select a category
    var p = Prompt.create();
    p.title = "Select list";
    for (var cat of categories) {
    	p.addButton(cat);
    }
    
    if (p.show()) { // user made a selection
    	var category = p.buttonPressed;
    	// query for list drafts...
    	var drafts = Draft.query(category, "inbox", [listTag]);
    	// loop over found drafts looking for a matching list
    	var d;
    	for (var draft of drafts) {
    		if (draft.content.startsWith("## " + category)) {
    			d = draft;
    		}
    	}
    	// if we didn't find the list, create it...
    	if (!d) {
    		d = Draft.create();
    		d.content = "## " + category + "\n\n";
    	}
    	// tag and update content
    	d.addTag(listTag);
    	d.content = d.content + "- [ ] " + currentContent + "\n"
    	d.update();
    }
    else { // user cancelled prompt
    	context.cancel();
    }

Options

  • After Success Archive
    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.