Action
Clipboard…
Clipboard Mega Action
Steps
-
script
//Clipboard Mega Action /* Action created by Tim Nahumck */ var actions = ["Copy","Append","Prepend","Copy to HTML","Copy as Rich Text","Copy UUID","Copy Link to Draft","Show","Paste","Clear"]; var p = Prompt.create(); p.title = "Select Clipboard Action"; for (i = 0; i < actions.length; i++) { p.addButton(actions[i]); } var con = p.show(); if (con) { var s = editor.getSelectedText(); var selRange = editor.getSelectedRange(); //Actions based on button presses if (p.buttonPressed == "Copy") { var text = draft.processTemplate("[[draft]]"); var clipboard = app.setClipboard(text); } if (p.buttonPressed == "Append") { var dtext = draft.processTemplate("[[draft]]"); var text = app.getClipboard() + dtext; var clipboard = app.setClipboard(text); } if (p.buttonPressed == "Prepend") { var dtext = draft.processTemplate("[[draft]]"); var text = dtext + app.getClipboard(); var clipboard = app.setClipboard(text); } if (p.buttonPressed == "Copy to HTML") { var text = draft.processTemplate("%%[[draft]]%%"); var clipboard = app.setClipboard(text); } if (p.buttonPressed == "Copy as Rich Text") { // Process Markdown to HTML var mmd = MultiMarkdown.create(); var html = mmd.render(draft.content); // Wrap raw MMD output with HTML template with styles to set base fonts. var template = "<html><style>body{font-family:'Helvetica';font-size:100%;}</style><body>[[content]]</body></html>" var html = template.replace("[[content]]", html); // Place in clipboard as rich-text if (!app.htmlToClipboard(html)) { context.fail("Error rendering rich text from HTML."); } } if (p.buttonPressed == "Copy UUID") { var text = draft.processTemplate("[[uuid]]"); var clipboard = app.setClipboard(text); } if (p.buttonPressed == "Copy Link to Draft") { var dtext = draft.processTemplate("[[uuid]]"); var text = "drafts5://x-callback-url/open?uuid="+dtext; var clipboard = app.setClipboard(text); } if (p.buttonPressed == "Show") { var clipboard = app.getClipboard(); alert(clipboard); } if (p.buttonPressed == "Clear") { var text = ""; var clipboard = app.setClipboard(text); } if (p.buttonPressed == "Paste") { var clipboard = app.getClipboard(); editor.setSelectedText(clipboard); } } else { context.cancel(); }
Options
-
After Success Default Notification Error Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.