Add same text to multiple selected drafts?

I couldn’t find an answer so just wondering, is there an action or a simple way to add the same text to multiple selected drafts? Presumably an action that applies to either one or multiple selected drafts (using Run Action)? Apologies if this is a dumb question. Thanks.

1 Like

Basically, create an action that does the appending to a single draft the way you want it to happen, then use “Run Action” to run that on each of the selected drafts in the list.

In the simple case, that should be just a basic two-line script action step, something like:

draft.append("TEXT TO APPEND")
1 Like

as an extension to the question (and your script), access via script to selections, could a future release have something like:

App.getSelectedDrafts (array of drafts already selected),
App.selectDrafts (plural, perhaps less confusing, .selectDraftsArray or similar)

Apologies as I assume the question did not come form someone familiar with scripting, so I will be elementary in my example below – I can see alternate ways (not using the full Drafts selection process, but building an array within script – based on tag, workspace, etc.) The process is:

  1. Add “tempz” as a tag (temporary, or permanent) to whatever drafts you want in the group (or use any unique tag(s) for whatever project you desire), or workspace. THIS IS A METHOD OF DESIGNATING A DRAFTS GROUP

2 script: (
a. copy the SCRIPT lines below,
b. then create a draft action, name it (your choice, e.g., ‘append to tagged drafts’)
c. add a single action step as a script (“script” action step is near the bottom of step types, 1st one under ‘Advanced’.,
d. edit the script step.,
e. paste this into the script action step edit, SAVE the edit, back out
f. execute the newly created action step:

// Brief skeleton script to do the same thing to every draft with a given tag
// lines starting with '//', like this one, are only comments, not actual parts of the script
// 2 variables, a tag name and the text to be entered
let tempTag = "tempz" // change as desired, but leave within quotes
let addOnText = "whatever text to append" // target words
// they do not need to be hard-coded, as they are here. 
// 'SELECT' you group of drafts
let dList = Draft.query("","all",[tempTag]) // gives an array of drafts with that tag
           // change "all" to "inbox", or "archive",  or "trash" if desired to so restrict
           // the first "" will retrieve all drafts that meet the location and tag criteria
           // using "SearchText" (or any text)  rather than the first "" filters for drafts containing "SearchText"
           //       that is an ALTERNATIVE to using TAG(S), IF your desired  group of drafts all have the same search temp, BUT NO OTHER DRAFTS DO. 
          //    If using only this text-search option, change the query to: 
          //         dList = Draft.query("searchterm","all");      // , leaving out the tag portion

// dList now contains an array of your drafts, process them one at a time:
for (d of dList) {        
     }      // end of processing each d in dList
// this ends the script

//  that example appends text on a new line, 
//  change the d.append line or add several  to do whatever actions you desire, prepend, add after title, change title, etc. 
//  d.removeTag is OPTIONAL -- if truly a temporary tag, else delete this line (or comment out) to keep the tag in place
//this could be modified slightly to take an actual workspace, or multiple tags, etc -- this is the simplest one TEMPORARY tag approach, and deletes the tag after processing.     


oh, a quick addition to the wordy above response, adding temporary tag en masse.

if you are used to selecting from the draft list sidebar, do the selecting, hit the 2-gears icon for options [on ios, bottom, the icon is next to where “select” has been replaced by “cancel”, and then “add tag” (greyed out and inactive if no drafts selected)]. Adds very little time after selection process.

You can get the selected drafts in a script with app.currentWindow.selectedDrafts (docs).

Note that you would not use this in combination with “Select > Gears > Run Action”, which runs an action individually on each of the selected drafts.

1 Like

thanks, there is so much depth in Draft’s offerings, and I had not looked deeply into Window; plus, as an old Fortran programmer, I am not used to stacking together so many layers.

so, for his original question of actively selected drafts or an individual draft, a script would be:

// auto-add/edit to all Selected Drafts, or current draft
// variable definitions
vr dList = []; // define empty array, not technically necessary here
var addOnText = “Whatever text strings you want” ;
var txt1 = “stormy weather”, txt2 = “storms” ;
// here, these variables are hard coded, and can be edited as an action step any/everytime
// but usually should be asked/defined in script, or in prior action step(s). Look at prompts.
dList = app.currentWindow.selectedDrafts; // get array of all drafts selected in this window
if (dList.length==0) { dList.push(draft); }
// OPTIONAL – if no selection(s), use the single current draft
for (d of dList) {
d.append(addOnText) // or do whatever you want done
// another EXAMPLE –
// d.content = d.content.replaceAll(txt1,txt2); // remove the comment bars to activate
} // end of processing each d in dList
// this ends the script

It is best to put script between triple back ticks for formatting on the forum. Solves a lot of quirkiness with readability and smart quotes that the forum otherwise introduces and as you can probably see above.


var foo = "bar";


var foo = “bar”

vr dList = []; // define empty array, not technically necessary here is missing an “a” in var, but for better code safety, you should generally use let over var.

Take a look at forEach() and/or map() array prototypes for your processing of the array of drafts. I don’t imagine it makes much of a difference here overall, but they can generally simplify iterating through an array.