Editorial Workflows


public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Brings up action sheet to tweet selected content. If selection is longer than 140 characters, it is broken up into multiple, appropriately sized smaller tweets. Each tweet includes a tweet counter to indicate to followers that it is part of a series of tweets.

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
If… ?
Run the block if
Selected Text
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Stop ?
  • This Workflow
  • Repeat Block
Show HUD Alert
…End If
Selected Text ?
Entire Line(s)
Empty Selection Output
  • No Output
  • All Text
  • Closest Word
Folded Text
  • Include
  • Replace with:
Run Python Script ?
Source Code
# Andrew Clark
# @acdlite

#coding: utf-8
import re
import workflow

# Functions
def split_tweets(content, placeholder='x'):
   tweets = []
   c = content
   while len(c) > 0:
       tweet_number = " ({0}/{1})".format(len(tweets)+1, placeholder)
       force_suffix = False

       if len(c) <= 140-len(tweet_number):
           suffix = tweet_number
           force_suffix = True
           suffix = u'\u2026' + tweet_number 

       if len(tweets) == 0:
           t, l = smart_truncate(c, 140, suffix)
           t, l = smart_truncate(c, 139, suffix, force_suffix)
           tweets.append(u'\u2026' + t.lstrip())

       c = c[l:].rstrip()
   return tweets

def smart_truncate(content, length=100, suffix='...', force_suffix=False):
   if  len(content) <= length and not force_suffix:
       return (content, len(content))
   elif len(content) <= length-len(suffix) and force_suffix:
       return (content + suffix, len(content))
       c = ' '.join(content[:length-len(suffix)].split(' ')[0:-1])
       return (c + suffix, len(c))

# Body

action_in = workflow.get_input()

tweets = []
placeholder = 'x' # Used in body of tweet; will be replaced with total number of tweets
cont = True

while cont:
   tweets = split_tweets(action_in, placeholder)
   # If the number of digits in total number of tweets exceeds length of placeholder
   # try again with incremented placeholder length
   cont = len(str(abs(len(tweets)))) > len(placeholder)
   if cont:
       placeholder = ''.join(['x' for i in range(len(placeholder)+1)])
# Replace placeholder with total number of tweets
reg = re.compile("{0}\)$".format(placeholder))
tweets = [reg.sub("{0})".format(len(tweets)), t) for t in tweets]

#TODO: Generate the output...
action_out = '{tweet}' + '\n{tweet}'.join(tweets)

Repeat… ?
Repeat with
  • Every Line
  • Every Match of Regular Expression:
Match Group
0 (entire match)
Find / Replace ?
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
Compose Tweet ?
Initial Text
Stop if Canceled
…End Repeat