Drafts Action Directory

Events in Fantastical

Posted by @nahumck, Last update 5 months ago - Unlisted

Split draft into lines and create events for each using Fantastical. Action created by @agiletortoise.

Install

Steps

  • script

    // check to see if draft is blank
    var content = draft.content;
    var check = content.length;
    if (content.length == 0) {
    	alert("Draft is blank");
    	context.cancel("Draft was blank");
    }
    // if content, remove blank lines from draft
    else {
      draft.content = draft.content.replace(/$\s*\n+/gm, "\n");
      draft.update();
    }
    
    // Open callback URL for each line in a draft
    // Setup base Fantastical URL, with no parameters
    const baseURL = "fantastical2://x-callback-url/parse/";
    
    // split draft and loop over lines
    var lines = draft.content.split("\n");
    for (var line of lines) {
    	// create and configure callback object
    	var cb = CallbackURL.create();
    	cb.baseURL = baseURL;
    	cb.addParameter("sentence", line);
    //	cb.addParameter("reminder", "1");
    	cb.addParameter("add", "1");
    	// open and wait for result
    	var success = cb.open();
    	if (success) {
    		console.log("Event created");
    	}
    	else { // something went wrong or was cancelled
    	  	console.log(cb.status);
    	  	if (cb.status == "cancel") {
    			context.cancel();
    		}
    		else {
    			context.fail();
    		}
    	}
    }
    

Options

  • After Success Default
    Notification Info
    Log Level Error
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.