Drafts Action Directory

Twitter Splitter

Posted by @rosemaryorchard, Last update 5 months ago

Splits the text into blocks of at most 275 characters (depending on the position of the space), which allows for indexing. You can optionally add indexing (1/5), or not depending on your preferences. The text is split with “===”.

Install

Steps

  • script

    // See online documentation for examples
    // http://getdrafts.com/scripting
    
    var p = Prompt.create();
    
    p.title = "Twitter Splitter";
    
    p.addButton("Add Index");
    p.addButton("No Index");
    p.addButton("No Space for Index");
    
    var didSelect = p.show();
    if (didSelect == "No Space for Index") {
    	var maxLength = 280;
    } else {
    	var maxLength = 274;
    }
    
    var content = editor.getText();
    var tweets = [];
    
    while (content.length > maxLength) {
    	var s = content.substr(0, maxLength);
    	var i = s.lastIndexOf(" ");
    	tweets.push(content.substr(0, i));
    	content = (content.substr(i+1, content.length));
    }
    
    if (p.buttonPressed == "Add Index") {
    	var text = "";
    	for (var i = 0; i < tweets.length; i++) {
    		text += tweets[i] + " " + (i+1) + "/" + tweets.length + "\n===\n";
    	}
    	editor.setText(text);
    } else {
    	editor.setText(tweets.join("\n===\n"));
    }

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.