Action
Book quote
Posted by mark_boerger,
Last update
7 days ago
UPDATES
7 days ago
Cleaned up formatting a bit.
Takes a bit of text, puts quotes around it, prompts for a page number, then provides a default author that can be changed out easily.
Steps
-
script
// See online documentation for examples // https://docs.getdrafts.com/docs/actions/scripting // === CONFIGURABLE DEFAULTS === let defaultAuthor = "C.S. Lewis"; // Change this as needed let defaultTitle = "Mere Christianity"; // Change this as needed // === GET SELECTED TEXT OR FULL DRAFT === let content = editor.getSelectedText(); if (content.length === 0) { content = editor.getText(); } // === CLEAN & WRAP QUOTE === let quote = `"${content.trim()}"`; // === PROMPT FOR PAGE NUMBER === let pagePrompt = Prompt.create(); pagePrompt.title = "Page Number"; pagePrompt.message = "Enter the page number for this quote:"; pagePrompt.addTextField("page", "Page", ""); pagePrompt.addButton("Next"); if (!pagePrompt.show()) { context.cancel(); } let pageNumber = pagePrompt.fieldValues["page"]; // === PROMPT FOR AUTHOR NAME === let authorPrompt = Prompt.create(); authorPrompt.title = "Author Name"; authorPrompt.message = "Enter the author of this quote:"; authorPrompt.addTextField("author", "Author", defaultAuthor); authorPrompt.addButton("Next"); if (!authorPrompt.show()) { context.cancel(); } let author = authorPrompt.fieldValues["author"]; // === PROMPT FOR BOOK TITLE === let titlePrompt = Prompt.create(); titlePrompt.title = "Book Title"; titlePrompt.message = "Enter the book title for this quote:"; titlePrompt.addTextField("title", "Title", defaultTitle); titlePrompt.addButton("Done"); if (!titlePrompt.show()) { context.cancel(); } let bookTitle = titlePrompt.fieldValues["title"]; // === FORMAT FINAL OUTPUT === let formatted = `${quote} — ${author}, *${bookTitle},* ${pageNumber}.`; // === REPLACE TEXT === if (editor.getSelectedText().length > 0) { editor.setSelectedText(formatted); } else { editor.setText(formatted); }
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.