Editorial Workflows

org sort by status and priority

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: Org-mode: Sort entire document as an org-mode todo list at top (1 star) level. First by status (TODO or DONE) and then by priority ([#A],[#B], etc.). Children stay with parents. Items with a status are treated as TODO. Items without a priority are treated as B. V1.1
http://orgmode.org
- stophlong

Shared by: stophlong

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Comment ?
Text
The first find/replace adds priority and staus info to items without either. The second adds priority to those without. the python script does the sorting. the next 2 find/replace functions remove the labels added by first two.
A document must be open... ?
Run the block if
File Name
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
ON
Message
No Document Selected
…End If
Extend Selection ?
Direction
  • Backward
  • Forward
  • Both
Unit
  • Start/End of Document
  • Start/End of Line
  • Number of Characters...
1
Find / Replace ?
Find
^(\#?\*|\#)(\s)[^(TODO)|(DONE)]
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
$1$2TODO [#Bzz]
Find / Replace ?
Find
^(\#?\*|\#)(\s)(TODO|DONE)(\s)(\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}\s)?([^\[])
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
$1$2$3$4$5[#Bz] $6
Run Python Script ?
Source Code
#coding: utf-8
import workflow

the_mark ='* '
the_split='\n' + the_mark
the_todo =the_mark + 'TODO '
the_todo_split='\n' + the_todo

the_input =  workflow.get_input() 

# add prefix and suffix so splitting works right
action_in = '\n' + the_input + the_split

# split and remove first and last which were from prefix+suffix
my_list = action_in.split(the_split)[1:-1]

#print('\n\n\n\n')
#print(my_list)

# check if standard org mark fails and try hybrid
if len(my_list)==0:
	the_mark ='#* '
	the_split='\n' + the_mark
	# add prefix and suffix so splitting works right
	action_in = '\n' + the_input + the_split

	# split and remove first and last which were from prefix+suffix
	my_list = action_in.split(the_split)[1:-1]

# then try md
if len(my_list)==0:
	the_mark ='# '
	the_split='\n' + the_mark
	# add prefix and suffix so splitting works right
	action_in = '\n' + the_input + the_split

	# split and remove first and last which were from prefix+suffix
	my_list = action_in.split(the_split)[1:-1]

the_todo =the_mark + 'TODO '
the_todo_split='\n' + the_todo
the_done_placeholder = the_mark + 'DONE [#A]\n'

# sort all
list_sorted=sorted(my_list)

# repair lines and add header to deal with case with no done
action_out1 = the_done_placeholder + the_mark + the_split.join(list_sorted)

#print(action_out1)

# move done to bottom by cutting at first todo
my_list2 = action_out1.split(the_todo_split)

#print(my_list2)

action_out2 =  the_todo + the_todo_split.join(my_list2[1:]) + '\n' + my_list2[0][12:]

#print(action_out2)

workflow.set_output(action_out2)
Find / Replace ?
Find
^(\#?\*|\#)(\s)(TODO|DONE)(\s)(\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}\s)?(\[\#Bz\] )
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
$1$2$3$4$5
Find / Replace ?
Find
^(\#?\*|\#)(\s)(TODO)(\s)(\[\#Bzz\] )
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
$1$2$4
Replace Selected Text ?
Replacement Text
Input
Move Caret ?
Direction
  • Backward
  • Forward
  • Start/End of Document
  • Start/End of Line
  • Number of Characters:
1