Action

Menu/prompt from draft contents

Posted by jsamlarose, Last update over 2 years ago - Unlisted

Select an item (from a list stored in a draft) to insert at the cursor.

Install this action first: https://actions.getdrafts.com/g/10X and remember to update this action with the UUID for the draft that contains your menu options.

Steps

  • includeAction

    name
    MGCheckListPrompt Library
  • script

    var i = 0;
    var myList = []
    var myItems = Draft.find("YOUR-UUID-HERE")
    myItems = myItems.lines
    var indexToRemove = 0;
    var numberToRemove = 2;
    
        myItems.splice(indexToRemove, numberToRemove)
    
    while(myItems[i]){
    
    		myList.push({
    						title: myItems[i] // .split(":")[0],
    						// description: myItems[i]
            			});
        	
    	i++;
    	}
    
    
    // Create an MGCheckListPrompt.
    var prompt = new MGCheckListPrompt();
    prompt.message = "Query: ";
    prompt.addItems(myList)
    prompt.allowsTypeToFilter = true
    prompt.singleSelectionMode = true
    prompt.selectsImmediately = true
    prompt.includedContent = `
    <style>
    .item-description {
    	font-size: 90%;
    	display: inline;
    }
    </style>
    `
    
    // Show the prompt.
    var selectedItems = prompt.show();
    
    // Report the result.
    if (prompt.didShow) {
    	if (selectedItems != null) {
    		insPos = editor.getSelectedLineRange()
    		editor.setSelectedRange(insPos[0]+insPos[1],0)
    		editor.setSelectedText(myList[selectedItems[0]].title) // + "\n")
    		var range = editor.getSelectedRange()
    		editor.setSelectedRange(range[0]+range[1],0)
    		editor.activate();
    	} else {
    		
    	}
    } else {
    	app.displayErrorMessage("Something went wrong.");
    	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.