Action
Import URL
Posted by agiletortoise,
Last update
over 4 years ago
Prompt for a URL and download the raw content of that URL and place it in a new draft.
Steps
-
script
// import content of a URL // prompt for URL let p = Prompt.create(); p.title = "Import URL"; p.message = "Enter URL to import" let initialText = ""; // use clipboard if it's a URL let clipboard = app.getClipboard(); if (clipboard.startsWith("http")) { initialText = clipboard; } p.addTextField("url", "URL", initialText, {"autocorrect": false, "autocapitalization": false}); p.addButton("Import"); if (p.show()) { // display prompt // get url and load with HTTP GET request let url = p.fieldValues["url"]; let http = HTTP.create(); let response = http.request({ "url": url, "method": "GET" }); if (response.success) { // if response came back, create new draft let text = response.responseText; let d = Draft.create(); d.content = text; d.update(); editor.load(d); } else { context.fail(); } } else { context.cancel(); }
Options
-
After Success Default Notification Info Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.