MGCheckListPrompt Paste selection in current draft

I downloaded the action group MGCheckListPrompt (many thanks to @mattgemmell ) and I’m trying to copy the content of the selected draft (the array of selected drafts if possible) in my current draft.

I’m new to scripting and after several trials and errors, I learned a lot about scripting but I still can’t figure out what to write.
I understand that editor.setSelectedText() should be used after
var selectedItems =;
, perhaps using a variable defined in the action group’s Code Library (MGCheckListPrompt Library).

Any help would be greatly appreciated.

See if this gets you on the right track.

I modified one of the standard demo actions to display the content of each selected draft as an alert.

The prompt looks to be returning an array of the indices of the original selection, so it is just a case of getting the content of those selections and processing it as you wish.

Hope that helps.

Thank you @sylumer, very appreciated.
I got it to work like this:

if (prompt.didShow) {
	if (selectedItems != null) { => 
([st, len] = editor.getSelectedRange(), 
s = (drafts[intIndex].content), 
editor.setTextInRange(st, s.length, s),
editor.setSelectedRange(st+s.length, 0)))

Probably not the most elegant, but it works.
Now, when I select several items, I would like every item to start at the beginning of a line. I’m trying to add +"\n\n" next to a variable I just described, with no success. Any clue?

Do you know about joining arrays in JavaScript?

I think it might be ideally suited if you built an array of draft content from the array of selected draft indices.

No but I will take a look.

It works well like this:

// Report the result.
if (prompt.didShow) {
	if (selectedItems != null) {
		let m = => 
		let s = m.join("\n");


Thanks again for your help.