Drafts Action Directory

Jump to TP Project

Posted by derick, Last update 3 months ago

Pick a TaskPaper project in the text and jump to it

Install

Steps

  • script

    // See online documentation for examples
    // http://getdrafts.com/scripting
    
    // script adapted from http://1writerapp.com/action/072ca
    
    var content,
        lines,
        headings,
        lengths,
        ranges,
        linesLength,
        i;
    
    content = editor.getText();
    lines = content.split('\n');
    linesLength = lines.length;
    lengths = 0;
    headings = Array();
    ranges = Array();
    
    for(i = 0; i < linesLength; i++) {
        if(lines[i].match(/.*:/)) {
            headings.push(lines[i]);
            ranges.push(lengths);
        }
        lengths += lines[i].length + 1; // +1 because the line breaks count;
    }
    
    var p = Prompt.create();
    
    if (headings.length > 0) {
    	p.addSelect("headings","Jump to Project",headings,[],false);
    	p.addButton("Go");
    } else {
       p.title = "No projects";
    }
    
    p.show();
    
    if (p.buttonPressed = "Go") {
    	var h = p.fieldValues["headings"][0];
    	if (h == undefined) {
    		alert ("No project selected"); 
    		} else {
    		var r = ranges[headings.findIndex(sel => sel == h)];
    		editor.setSelectedRange(r);
          }
    };
    
    

Options

  • After Success Default
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.