Action

Make Work Fun

Posted by Garbonsai, Last update about 3 years ago

UPDATES

about 3 years ago

Use template tags to define what words should be skipped and the minimum word length required when choosing a random word from the currect draft.

Select a random word from the current draft and create a temporary workspace showing all flagged drafts that contain the same word. Skips words listed in the comma-separated “exclusions” template tag and words with fewer characters than “minimum”. Meant for triaging flagged drafts—edit the “ws.loadFolder” and “ws.setFlaggedSort” lines to repurpose.

Steps

  • defineTemplateTag

    name
    exclusions
    template
    the, be, to, of, and, a, in, that, have, i, it, for, not, on, with, he, as, you, do, at, this, but, his, by, from, they, we, say, her, she, or, an, will, my, one, all, would, there, their, what, so, up, out, if, about, who, get, which, go, me, when, make, can, like, time, no, just, him, know, take, people, into, year, your, good, some, could, them, see, other, than, then, now, look, only, come, its, over, think, also, back, after, use, two, how, our, work, first, well, way, even, new, want, because, any, these, give, day, most, us
  • defineTemplateTag

    name
    minimum
    template
    6
  • script

    // get settings from template tags
    let exclusions = draft
    	.getTemplateTag( 'exclusions' )
    	.split( ',' )
    	.map( exclusion => exclusion.trim() );
    let min = parseInt( draft.getTemplateTag( 'minimum' ) );
    
    // convert the text of the current draft into an array of unique words
    let words = editor
    	.getText()
    	.toLowerCase()
    	.replace( /\W/g, ' ' )
    	.split( ' ' );
    let uniques = [ ...new Set( words ) ];
    
    // remove any exclusions or too-short words from the array
    let rares = uniques.filter( word => !exclusions.includes( word ) && word.length > min );
    
    // select a word at random
    let random = rares[ Math.floor( Math.random() * rares.length ) ];
    
    // build a temporary workspace
    let ws = Workspace.create();
    ws.loadFolder = 'flagged';
    ws.name = '“' + random + '” Drafts';
    ws.queryString = random;
    ws.setFlaggedSort( 'name', false );
    
    // load the temporary workspace
    app.applyWorkspace( ws );
    app.showDraftList();

Options

  • After Success Nothing
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.