Action

retitle current Draft

Posted by @FlohGro, Last update 8 months ago

retitle current Draft

Created by FlohGro (Twitter)

This action creates a Prompt which displays the title of the current Draft. You can edit the title in the text field and choose to either save the edits (which replaces the current title) or choose to prepend the edit as a new title of the Draft.
You can use this action on its own or include it in other ones to change the title before sharing the draft somewhere.

note: this action does not check for syntax of the Draft, so if you have e.g. a markdown note make sure to keep the heading symbols in the text field!

If you find this useful you can Buy Me A Coffee

Steps

  • script

    // retitle current Draft
    // Created by @FlohGro - inspired by @AlexWinn
    
    var p = Prompt.create();
    p.title = "retitle Draft";
    p.addTextField("newTitle", "title", draft.title);
    p.addButton("set title");
    p.addButton("prepend new title");
    
    var con = p.show();
    
    if (con) {
        switch (p.buttonPressed) {
            case "set title":
                // modify content of draft.title by splitting the content - first line is the title
                let draftContentArray = draft.content.split("\n")
                draftContentArray[0] = p.fieldValues["newTitle"];
                draft.content = draftContentArray.join("\n")
                draft.update();
                break;
            case "prepend new title":
                draft.prepend(p.fieldValues["newTitle"], "\n\n");
                draft.update()
                break;
        }
    } else {
        context.cancel();
    }

Options

  • 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.