Drafts Action Directory

Save to Dropbox & Create Share Link

Posted by agiletortoise, Last update 7 days ago

Save to timestamped file in Dropbox, then generate a share URL to that file and place it in the clipboard.

This action is demonstration of more advanced Dropbox API support possible with the Dropbox scripting object.

Install

Steps

  • script

    // options
    let path = "/" + draft.processTemplate("[[time]].txt");
    let content = draft.content;
    
    
    // write file to Dropbox
    let db = Dropbox.create();
    db.write(path, content, "overwrite", false);
    
    // generate share link and place it in clipboard
    let endpoint = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings";
    let args = {
    	"path": path,
    	"settings": {
    		"requested_visibility": "public"
    	}
    };
    let response = db.rpcRequest({
    	"url": endpoint,
    	"method": "POST",
    	"data": args
    });
    
    if (response.statusCode == 200) {
    	let shareURL = response.responseData["url"];
    
    	let p = Prompt.create();
    	p.title = "Dropbox file created";
    	p.message = "File \"" + path + "\" created and link generated.";
    
    	p.addButton("Copy Link");
    	p.addButton("Open URL in Safari");
    
    	if (p.show()) {
    		if (p.buttonPressed == "Copy Link") {
    			app.setClipboard(shareURL);
    		}
    		else if (p.buttonPressed == "Open Link") {
    			app.openURL(shareURL);
    		}
    	}
    }

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.