Action

Random Quote

Posted by sylumer, Last update over 2 years ago - Unlisted

Steps

  • script

    // Set your own tag, here or in a script step before you include this action, if you'd like to bypass the prompt
    
    // let tag = 'goals'
    
    if (typeof tag === 'undefined') {
      tag = [""]
    } else if (typeof tag === 'string') {
      tag = [tag]
    }
    
    function randomDraft(tag) {
    
      if (!tag[0])
      { 
        const p = Prompt.create()
        p.title = "Choose tag to open random draft"
        p.message = "Leave unselected to pick any random draft"
        p.addSelect("tag", "", Draft.recentTags(), [], false)
    
        p.addButton("Choose")
    
        if (p.show())
          tag = p.fieldValues["tag"]
      }
    
      let matchingDrafts = Draft.query("", "all", tag).filter(d => d.uuid != draft.uuid)
    
      if (matchingDrafts.length == 0) return
        
      const randomDraft = matchingDrafts[Math.floor(Math.random() * matchingDrafts.length)]
    
      //app.openURL(`drafts5://x-callback-url/open?uuid=${randomDraft.uuid}`)
      return randomDraft.uuid;
    }
    
    //randomDraft(tag)
    
    var fullFragDraft = Draft.find(randomDraft(tag));
    var splitFrag = fullFragDraft.lines
    
    
    // this is whete I'd like to filter lines based on words inside i.e. include lines with the text "#Modern" and exclude any lines witn the text "#question"
    
    var filteredFrag = splitFrag
    var numLines = filteredFrag.length
    var RandLine = Math.round(Math.random() * numLines)
    var ResultLine = splitFrag [RandLine]
    
    draft.append ("\n\n" + RandLine + "\n" + filteredFrag.length + "\n" + ResultLine + "\n");
    
    
    

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.