Editorial Workflows

trimpad

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: Trimpad is a simple action demo-ing a python script to adjust any string to a given length (trimmed shorter or padded longer), positioning the str right,left, or center justified. Options on how to pass variables into it are commented in the script.

I developed for fixed column widths (requires monospace fonts)

should be opened to see, but only the python script step "trimpad" can be saved as a command -- the rest is demonstration

Shared by: lacsmith

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Set Variable ?
Variable Name
trimpadlen
Value
4
Set Variable ?
Variable Name
trimpadpos
Value
>
Console Output ?
Text
>12abcdefghijklmnopqrstuvwxyz** this is the input to the python code trimpad
Generate Text ?
Text
>12abcdefghijklmnopqrstuvwxyz
trimpad ?
Source Code
#coding: utf-8
import workflow
# this is to pad(add spaces) or trim(truncate) input string to a given number of chars, 
# and to right,left, or center justify. Will always return a str of given length
# see next few lines for modes of entry
#
#accumulate variables
#
# EITHER define the variables below before coming in, 
# or INPUT (set var. or gen. text) as format-type+length(2 digits)+inputstr-e.g.,">04this is it"
#
# if used, trimpadlen,trimpadpos, and trimpadstr must be defined (set variable) in calling program
# could configure variable trimpadstr similarly, but now set as input (see below)
#
# trimpadlen will be the resulting length— either padded or truncated
# trimpadpos is the format ("<" ">" or "^" as single char. for left, right, center justified
#   and spaces added as needed— see python docs on str.rjust() to change the added spaces to else)
action_in = workflow.get_input()
# or to use get variable approach, remove the comment mark next lines
#action_in = int(workflow.get_variable("trimpadstr"))
#trim_len = int(workflow.get_variable("trimpadlen"))
#trim_pos = workflow.get_variable("trimpadpos")
#
# next three lines if the input strng begins with 1 char position and 2 char integer, 
# else comment out and activate above lines
trim_pos = action_in[0:1]
trim_len = int(action_in[1:3])
action_in = action_in[3:]
length_in = len(action_in)
#TODO: Generate the output...
# check length to see if trimming needed
if length_in > trim_len:
	 action_in = action_in[0:trim_len]
if trim_pos == "<" :
  action_out = action_in.ljust(trim_len)
if trim_pos == ">" : 
	action_out = action_in.rjust(trim_len)
if trim_pos == "^" :
	action_out = action_in.center(trim_len)
#
workflow.set_output(action_out)
Console Output ?
Text
***Input*** centered and truncated
Generate Text ?
Text
<12abcdef
trimpad ?
Source Code
#coding: utf-8
import workflow
# this is to pad(add spaces) or trim(truncate) input string to a given number of chars, 
# and to right,left, or center justify. Will always return a str of given length
# see next few lines for modes of entry
#
#accumulate variables
#
# EITHER define the variables below before coming in, 
# or INPUT (set var. or gen. text) as format-type+length(2 digits)+inputstr-e.g.,">04this is it"
#
# if used, trimpadlen,trimpadpos, and trimpadstr must be defined (set variable) in calling program
# could configure variable trimpadstr similarly, but now set as input (see below)
#
# trimpadlen will be the resulting length— either padded or truncated
# trimpadpos is the format ("<" ">" or "^" as single char. for left, right, center justified
#   and spaces added as needed— see python docs on str.rjust() to change the added spaces to else)
action_in = workflow.get_input()
# or to use get variable approach, remove the comment mark next lines
#action_in = int(workflow.get_variable("trimpadstr"))
#trim_len = int(workflow.get_variable("trimpadlen"))
#trim_pos = workflow.get_variable("trimpadpos")
#
# next three lines if the input strng begins with 1 char position and 2 char integer, 
# else comment out and activate above lines
trim_pos = action_in[0:1]
trim_len = int(action_in[1:3])
action_in = action_in[3:]
length_in = len(action_in)
#TODO: Generate the output...
# check length to see if trimming needed
if length_in > trim_len:
	 action_in = action_in[0:trim_len]
if trim_pos == "<" :
  action_out = action_in.ljust(trim_len)
if trim_pos == ">" : 
	action_out = action_in.rjust(trim_len)
if trim_pos == "^" :
	action_out = action_in.center(trim_len)
#
workflow.set_output(action_out)
Console Output ?
Text
***Input*** left justified and padded
Console Output ?
Text
<12abcdef** was the input to the python code trimpad