Action

Workspace Builder

Posted by Jake Bernstein, Last update about 1 month ago

Though still a WIP, this Action allows you to build up a temporary Workspace that will load immediately. There is an option to save the Workspace permanently as well.

Steps

  • script

    // See online documentation for examples
    // https://docs.getdrafts.com/docs/actions/scripting
    
    // Temporary Workspace Constructor for Building on-the-fly workspaces
    // should provide various checkboxes and stuff in a prompt. 
    
    // It works! Now to iterate. Tags should be have some select boxes too. 
    // Create option to save the workspace and add some more choices to the prompt around various WS variables!
    
    let coreTags = ["work", "notes", "call", "meeting", "draft", "reference"];
    let selectableTags = Array.from(new Set(coreTags));
    let initialTags = [];
    
    // Prompt for Workspace Variables
    var p = Prompt.create();
    p.title = "Create Workspace";
    p.addTextField("name", "Title", "");
    p.addSwitch("tagswitch", "Require All?", false);
    p.addSwitch("saveit", "Save Workspace?", false);
    p.addTextField("tagfilter","CS-Tags", "");
    p.addTextField("queryString", "Query?", "");
    p.addSelect("tags", "Tags for Filter", selectableTags, initialTags, true);
    p.addButton("Load Workspace");
    // var con = p.show();
    
    
    // unless you call `ws.update()`, this ws is temporary
    // load this workspace, and display draft list
    
    if (p.show()) {
    	let ws = Workspace.create();
    	ws.name = p.fieldValues["name"];
    	ws.tagFilter = p.fieldValues["tagfilter"]+","+p.fieldValues["tags"].join(",");
    	ws.queryString = p.fieldValues["queryString"];
    	ws.setInboxSort("modified", true);
    	ws.loadFolder = "all";
    	//  save for later, need to incorporate into tagFilter somehow, probably build up an array and then split it again.
    	if (p.fieldValues["tagswitch"]==true) {
    		ws.tagFilterRequireAll = true;
    		}
    		else if (p.fieldValues["tagswitch"]==false) {
    			ws.tagFilterRequireAll = false;
    			}
    app.applyWorkspace(ws);
    app.showDraftList();
    if (p.fieldValues["saveit"]==true) { 
    	ws.update();
    	}
    app.displayInfoMessage("Workspace created using " + p.fieldValues["tagfilter"]+","+p.fieldValues["tags"].join(",") + " as tag filter.");
    }
    
    
    
    // BEGIN config variables
    // setup tags or searches you wish to load...
    // let name = "Blue Things";
    // let tagFilter = "blue, !green"
    // let queryString = "";
    // END config variables
    
    // create workspace
    // for other options, see:
    // https://reference.getdrafts.com/objects/Workspace.html
    

Options

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