Accessing the Clipboard from Javascript

I have an action set up that lets me create a document that (in relevant part) includes a Bible passage obtained through an online API and pastes it into a broader template. I’m using the Insert ESV Text action from the Drafts Directory (here) to obtain a different passage each day; that action is set up, using Javascript, to provide a prompt to the user asking for the relevant passage, which it then submits to the API, ultimately returning the text of the passage.

I’d like to modify the action so that rather than prompting me for the relevant passage, it instead pulls the passage from the clipboard (i.e., the clipboard would already contain the text that I’d otherwise type into the prompt, and would just run automatically without requiring any interaction from the user). I’m almost completely Javascript-illiterate, though, and haven’t been able to figure out how to access the clipboard from within the script or to set a variable to the clipboard. (I’ve pasted the the script below; I think that what I need to do is set the “passage” variable to be the clipboard.)

Is there a way to accomplish that using javascript? (I tried defining a Template tag in Drafts and then using that template tag within the Script step of my action, but that did not work.) Thanks very much in advance for any help!

> // Insert Bible Verse into Drafts
> 
> // Store ESV API Token in the Drafts Credential Keychain. You will be prompted for your API Token
> 
> var credential = Credential.create("ESV", "ESV.org API");
> 
> credential.addPasswordField("API_Token", "API Token");
> 
> credential.authorize();
> var token = credential.getValue("API_Token");
> 
> // Create search prompt for Bible verses
> 
> var p = Prompt.create()
> p.title = "Bible Search";
> p.message = "What Passage From The Old Or New Testament Would You Like to Insert?";
> p.addTextField("query", "Passage", "Mark ")
> // Currently, the prompt defaults to inserting as a blockquote. If you want to change this default behavior, change the word "true" to "false" in the next line
> p.addSwitch("blockQuote", "Insert as Markdown Blockquote", false);
> p.addButton("Done");
> p.show();
> // Replace a space between book names and chapter/verse with a plus for URL purposes
> var passage = p.fieldValues["query"];
> var query = passage.replace(" ", "+");
> // Request Data from ESV API
> var http = HTTP.create();
> var response = http.request({
> 	"url": "https://api.esv.org/v3/passage/text/",
> 	"method": "GET",
> 	"parameters": {
> 		"q": query,
> 		"include-passage-references": "true",
> 		"include-footnotes": "false",
> 		"include-footnote-body": "false",
> 		"indent-poetry": "false",
> 		"indent-paragraphs": "false",
> 		"indent-declares": "false",
> 		"indent-psalm-doxology": "false"
> 	},
> 	"headers": {
> 	"Authorization": "Token " + token
> 	}
> });
> // Function to add Markdown Blockquotes to the beginning of each new line if the blockquote selector switch from the Prompt is toggled on.
> function addMarkdownQuote(text) {
> 	var lines = text.split("\n");
> 	var quoteLines = []
> 	for (var line of lines) {
> 		var blockQuote = "> " + line
> 		quoteLines.push(blockQuote);
> 	}
> 	var quote = quoteLines.join("\n");
> 	return quote
> }
> // Processes JSON response from ESV Server and converts to text
> function processVerses(rawJSON) {
> var json = JSON.parse(rawJSON);
> 	var bibleVerses = json.passages[0];
> 	if (p.fieldValues["blockQuote"] == true) {
> 		var finalQuote = addMarkdownQuote(bibleVerses);
> 	}
> 	else {
> 		var finalQuote = bibleVerses;
> 	}
> 	return finalQuote
> }
> // Response Success and Failure Options
> if (response.success) {
> 	var passageForInsert = processVerses(response.responseText);
> 	draft.setTemplateTag("passage", passageForInsert);
> }
> else {
> 	console.log(response.statusCode);
> 	console.log(response.error);
> }

Try commenting out the prompt related lines, but leave var passage = p.fieldValues["query"]; uncommented and change it to var passage = app.getClipboard();.

That should then stop the prompt processing being carried out and read the result it would have provided from the clipboard instead.

Thanks very much - that worked perfectly.