Action

Focus on linked excerpts

Posted by jsamlarose, Last update almost 5 years ago

Creates a new temp workspace that focuses on drafts that share the same title. Useful if you save multiple text excerpts from a single article or blog post as separate drafts. By default, the action captures the text section of the first markdown link in the current draft (retaining square brackets) and searches for other drafts that also contain the same text string.

Makes use of Greg’s “Load temp workspace” sample code, and works best with a share extension template that captures the title and url along with any text you’ve selected in Safari (or wherever you’re using the share extension to capture text).

Steps

  • script

    // See online documentation for examples
    // http://getdrafts.com/scripting
    
    
    // Use this if you're sure the title will always be a url
    var myTitle = /\[(.*?)\]/.exec(editor.getText())
    alert(myTitle[0])
    
    // Use this if you're happy to work with the title (first line) regardless of whether it's a link or not...
    // var myTitle = draft.title
    // alert(myTitle)
    
    // BEGIN config variables
    // setup tags or searches you wish to load...
    let name = myTitle[0];
    let tagFilter = ""
    let queryString = myTitle[0];
    // END config variables
    
    // create workspace
    // for other options, see:
    // https://reference.getdrafts.com/objects/Workspace.html
    let ws = Workspace.create();
    ws.name = name;
    ws.tagFilter = tagFilter;
    ws.queryString = queryString;
    ws.setInboxSort("created", false);
    
    // unless you call `ws.update()`, this ws is temporary
    // load this workspace, and display draft list
    
    app.applyWorkspace(ws);
    app.showDraftList();
    

Options

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