Editorial Workflows

InsertReference

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: This workflow displays a list of files from the current directory.

Select, Copy, and Continue the workflow to insert the copied text at the cursor position in the current document. The inserted content includes a Begin and End timestamp tags as well as the retrieved file name.

The workflow also gives the user the option to see the file's content in popover or full screen mode. Both views allow select, copy, and insertion of text.

Shared by: daveterry

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Stop if no document is open... ?
Run the block if
File Name
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Show Alert ?
Title
No document open...
Message
You need to open a document to use this workflow. It uses the current document's path to determine where to search.
Button 1
OK
Output Value
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
OFF
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
Get Current File Name ?
Include Folder
ON
Include Extension
OFF
Python script: get directory ?
Source Code
#coding: utf-8
import editor
import os
import sys
import workflow
import time

action_in = workflow.get_input()
# Global Variables
p = action_in
dir = os.path.split(p)[0]
          
action_out = dir
workflow.set_output(action_out)
Set Variable ?
Variable Name
path
Value
Input
Run Python Script ?
Source Code
#coding: utf-8
import editor
import os
import re
import sys
import workflow
import time

# User variables

sort_date = 0          # Default sorts by date, set to 0 to sort by name
reverse_order = True   # Default reverses order for sort by date, change to false for sort by name

# Global Variables
p = editor.get_path()
dir = os.path.split(p)[0]
valid_extensions = set(['.txt', '.md', '.markd', '.text', '.mdown', '.taskpaper','.markdown','.org'])
search_index = {}
action_sort = []

# Main - Gather filenames from the current open document directory 

for (path, dirs, files) in os.walk(dir):
    for name in files:
       full_path = os.path.join(path, name)
       ext = os.path.splitext(full_path)[1]
       if ext.lower() not in valid_extensions:
           continue   
       else:
       	   modTime = os.stat(full_path).st_mtime
           search_index[name] = modTime

from collections import OrderedDict

for key in OrderedDict(sorted(search_index.items(), key=lambda t:t[sort_date], reverse=reverse_order)):
    action_sort.append(key)
          
action_out = '\n'.join(action_sort)
workflow.set_output(action_out)
Select from List ?
Title
Files in current directory
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
ON
Set Variable ?
Variable Name
SelectedFileName
Value
Input
Generate Text ?
Text
path/SelectedFileName
Set Variable ?
Variable Name
PathFile
Value
Input
Get File Contents ?
File Name
%var:PathFile
In Dropbox
ON
If File Does Not Exist
  • Empty Output
  • Stop Workflow
Set Variable ?
Variable Name
ReferenceContents
Value
Input
Set Variable ?
Variable Name
viewType
Value
popover
Set Variable ?
Variable Name
lines
Value
1 2 3 4 5 6 7 8 9
Generate Text ?
Text
lines
Repeat… ?
Repeat with
  • Every Line
  • Every Match of Regular Expression:
Match Group
0 (entire match)
Reverse
OFF
If "popover" view requested ... ?
Run the block if
viewType
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
popover
Insert Reference - Popover ?
User Interface
Presentation Style
  • Sheet
  • Full-Screen
  • Popover
Output
Clipboard
Use Editor Theme
ON
…End If
If "page" view type requested ... ?
Run the block if
viewType
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
page
Insert Reference - Full Screen View ?
User Interface
Presentation Style
  • Sheet
  • Full-Screen
  • Popover
Output
Clipboard
Use Editor Theme
ON
…End If
If… ?
Run the block if
viewType
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
continue
Replace Selected Text ?
Replacement Text
### [Insert: Begin](Hour: 01 (24h)Minute: 01Second: 01 SelectedFileName) Clipboard ### [Insert: End](Hour: 01 (24h)Minute: 01Second: 01 SelectedFileName)
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
…End Repeat