Action

New Draft in Workspace

Posted by agiletortoise, Last update about 1 year ago

UPDATES

about 1 year ago

Warning that Pro features are required if not enabled.

Prompt to select a workspace, and create a new draft already assigned tags that match the tag filter for the workspace. Load the new draft in the editor.

Steps

  • script

    // select from a list of workspace and load
    
    let f = () => {
    	let workspaces = Workspace.getAll();
    	if (workspaces.length == 0) {
    		alert("No workspaces defined.");
    		return false;
    	}
    	
    	let p = Prompt.create();
    	p.title = "New Draft in Workspace";
    	p.message = "Select workspace. A new draft will be created and assigned tags to match the workspace.";
    	
    	let ix = 0;
    	for (let ws of workspaces) {
    		if (ws.tagFilter.length > 0 && ws.tagFilter.trim() != "untagged") {
    			p.addButton(ws.name, ix);
    		}
    		ix++;
    	}
    	
    	if (!p.show()) {
    		return false;
    	}
    	
    	let selectedIndex = p.buttonPressed;
    	let ws = workspaces[selectedIndex];
    
    	let tags = ws.tagFilter.split(",").filter(tag => tag.trim().length > 0 && tag.trim()[0] != "!" && tag.trim() != "untagged")
    	let d = Draft.create();
    	for (var tag of tags) {
    		d.addTag(tag);
    	}
    	d.update();
    	editor.load(d);
    	editor.activate();
    	return true;
    }
    
    if (app.isPro) {
    	if (!f()) {
    		context.cancel();
    	}
    }
    else {
    	alert("Drafts Pro features required to use this action.")
    }
    

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.