Drafts Script Reference

CallbackURL

CallbackURL objects can be used to open x-callback-url requests and wait for a response from the target app.

NOTE: If you want to open a URL in Safari or another app and do not need a response or x-callback-url support, use the app.openURL(url) method on the App object.

Properties

Functions

Class Functions

Examples

// 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);
	// 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();
		}
	}
}