Editorial Workflows

TF: Move to project

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: Move selected line to project in Taskpaper

Requires Python packages:
- Todoflow: https://github.com/bevesce/TodoFlow
- ply: https://github.com/dabeaz/ply
They are installed on first run so it can take a while.

Shared by: @bevesce

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
maybe install todoflow ?
Source Code
def install_todoflow():
    import urllib
    import zipfile
    import shutil
    import os

    def download_package(github_url, name, dir_name, before_dir_removal=lambda dir_name, name: None):
        zip_file = name + '-temp.zip'
        print 'downloading', github_url
        urllib.urlretrieve(github_url, zip_file)
        print 'extracting', zipfile
        z = zipfile.ZipFile(zip_file)
        z.extractall()
        try:
            shutil.rmtree(name)
        except OSError:
            pass
        os.remove(zip_file)
        print 'installing', name
        shutil.move(os.path.join(dir_name, name), name)
        before_dir_removal(dir_name, name)
        print 'cleaning'
        shutil.rmtree(dir_name)
        print 'done'

    download_package(
        'https://github.com/dabeaz/ply/archive/master.zip',
        'ply',
        'ply-master'
    )
    download_package(
        'https://github.com/bevesce/TodoFlow/archive/master.zip',
        'todoflow',
        'TodoFlow-master',
    )
    download_package(
        'https://github.com/bevesce/datedrop/archive/master.zip',
        'datedrop.py',
        'datedrop-master'
    )
    def fix_file(path, fixes):
        t = open(path).read()
        for tofix, replacement in fixes:
            t = t.replace(tofix, replacement)
        open(path, 'w').write(t)

    # its seems like editorial cant handle absolute or somerhing like that
    d = 'todoflow'
    for filename in os.listdir(d):
        if filename.endswith('py'):
            fix_file(
                os.path.join(d, filename), [
                    ['from __future__ import absolute_import', ''],
                    ['from . ', ''],
                    ['from .', 'from ']
                ]
            )
    

try:
	import todoflow
	import ply
	import datedrop
except:
	install_todoflow()
get projects ?
Source Code
#coding: utf-8
import workflow
import editor
import todoflow

text = editor.get_text()
todolist = todoflow.from_text(text)
projects = (str(t)[:-1] for t in todolist.search('type = "project"'))
action_out = '\n'.join(projects)

workflow.set_output(action_out)
select project ?
Title
Project
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Set Variable ?
Variable Name
project
Value
Input
Extend Selection ?
Direction
  • Backward
  • Forward
  • Both
Unit
  • Start/End of Document
  • Start/End of Line
  • Number of Characters...
1
Selected Text ?
Entire Line(s)
OFF
Empty Selection Output
  • No Output
  • All Text
  • Closest Word
Folded Text
  • Include
  • Replace with:
Set Variable ?
Variable Name
selected
Value
Input
Extend Selection ?
Direction
  • Backward
  • Forward
  • Both
Unit
  • Start/End of Document
  • Start/End of Line
  • Number of Characters...
1
Replace Selected Text ?
Replacement Text
move ?
Source Code
#coding: utf-8
import workflow
import editor 

toadd = workflow.get_variable('selected')
project = workflow.get_variable('project') + ':'
text = editor.get_text()

level = len(project) - len(project.lstrip()) + 1
toadd = '\t' * level + toadd.lstrip()

n = project + '\n' + toadd
s = text.find(project)
e = s + len(project)
editor.replace_text(s, e, n)