Post Gist to Github

Posted by agiletortoise, Last update about 4 years ago

Post the content of the draft to a Gist on Github. After creating the Gist, you are prompted to either place the URL in the clipboard, or open the Gist in Safari. The URL is also logged in the action log for reference.

When first run, you will be prompt to enter a personal access token for API access. Generate a token a your settings page on The token should have “gist” permissions for this action to work.

Basic configuration options for output content, public/private status can be configured in variables at the beginning of the script.


  • script

    /* Create public Gist with draft content on GitHub
    *. When first run, you will be prompted for a personal API token
    *  Personal tokens can be generated at:
    *  The token used should have "gist" scope permissions
    // BEGIN config
    let content = draft.content; // content of the Gist
    let fileName = ""; // file name
    let isPublic = true; // should this be a public Gist
    // END config 
    // do credential auth to get a token from the user.
    let auth = () => {
    	let githubPage = "";
    	let cred = Credential.create("GitHub Gist", "Enter personal access token for the GitHub API generated from your developer page at ( This token should have permissions for the scope \"gist\" to allow creation of Gists.");
    	cred.addTextField("Token", "");
    	if (cred.authorize()) {
    		return cred.getValue("Token");
    	else {
    		return false
    let token = auth();
    if (token) {
    	let http = HTTP.create();
    	let data = {
    	  "description": "Gist from Drafts",
    	  "public": isPublic,
    	  "files": { }  
    	data["files"][fileName] = {
    		"content": content
    	let settings = {
    	  "url": "",
    	  "method": "POST",
    	  "headers": {"Authorization": `Bearer ${token}`},
    	  "data": data
    	let response = http.request(settings);
    	if (response.statusCode == 201) {
    		let responseData = JSON.parse(response.responseText);
    		let gistURL = responseData.html_url;
    		console.log("Gist created");
    		let p = Prompt.create();
    		p.title = "Gist created"
    		p.message = "Gist created and url placed in the clipboard."
    		p.addButton("Open in Safari");
    		if ( {
    		  if (p.buttonPressed == "Open in Safari") {
    	else {
    else {


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