Action

Setup Project

Posted by agiletortoise, Last update almost 4 years ago

Create a workspace for a new project with a specific set of tags, and an initial table of contents draft.

After creating this workspace, additional sub-drafts can be added using the example “New Linked Draft” action.

Steps

  • script

    
    let f = () => {
    	// prompt for title and tags
    	let p = Prompt.create();
    	p.title = "Create Project Workspace"
    	p.message = "Create a workspace for a new project with a specific set of tags, and an initial TOC draft."
    	
    	p.addTextField("name", "Project Name", "");
    	p.addTextField("tags", "Tags", "");
    	p.addButton("Create");
    	
    	if (!p.show()) { return false; }
    	
    	let tags = p.fieldValues["tags"].split(",").map(s => s.trim());
    	let name = p.fieldValues["name"];
    	
    	if (tags.length == 0 || name.length == 0) {
    		alert("Name and at least one tag are required to create a project.");
    		return false;
    	}
    		
    	let w = Workspace.create();
    	w.name = name;
    	w.setInboxSort("name", false, true);
    	w.setFlaggedSort("name", false);
    	w.setArchiveSort("name", false, true);
    	w.inboxIncludesFlagged = true;
    	w.archiveIncludesFlagged = true;
    	w.showTags = true;
    	w.showPreview = true;
    	w.tagFilter = tags.join(",");
    	w.tagFilterRequireAll = true;
    	w.update();
    	
    	let d = Draft.create();
    	for (let tag of tags) {
    		d.addTag(tag);
    	}
    	d.content = `# ${name}: Table of Contents
    	
    	- `;
    	d.isFlagged = true;
    	d.update();
    	
    	app.applyWorkspace(w);
    	editor.load(d);
    		
    	return true;
    }
    
    if (!f()) {
    	context.cancel();
    }

Options

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