Action
Format for Plaintext Email
Posted by jmshrrsn ,
Last update
1 day ago
Formats Drafts content for Mail etc: bullets, plain headings, URLs preserved, address blocks skipped. Result copied to clipboard. This allows pasting to say Apple Mail and allows further editing, importantly, preserving original line and paragraph spacing.
Steps
-
script
// Get the draft content var text = draft.content.trim(); // Split into logical blocks var paragraphs = text.split(/\n{2,}/); var output = []; var hasHeading = false; // Date fallback var dateStamp = new Date().toLocaleDateString("en-GB", { day: '2-digit', month: 'short', year: 'numeric' }); paragraphs.forEach((p, i) => { p = p.trim(); // Multi-line block? if (p.includes('\n')) { let lines = p.split('\n').map(l => l.trim()); // Is it a block of bullet lines? if (lines.every(line => /^[-*]\s+/.test(line))) { lines.forEach(line => { output.push('➤\t' + line.replace(/^[-*]\s+/, '')); }); } // Otherwise, skip (likely an address) return; } // Headings (no underlining) if (/^#{1,2}\s/.test(p)) { hasHeading = true; var title = p.replace(/^#+\s*/, ''); output.push(title); return; } // Single-line bullet if (/^[-*]\s+/.test(p)) { output.push('➤\t' + p.replace(/^[-*]\s+/, '')); return; } // Raw URL — leave untouched if (/^https?:\/\/\S+$/i.test(p)) { output.push(p); return; } // Regular paragraph output.push(p); }); // Add heading with date if none was found if (!hasHeading) { output.unshift(`Email Notes — ${dateStamp}`); } // Join with double line spacing var finalOutput = output.join('\n\n'); // Copy to clipboard app.setClipboard(finalOutput); // Optional preview // editor.setText(finalOutput);
Options
-
After Success Nothing Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.