Editorial Workflows

Quick Search (with sort options)

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: **UPDATE to Quick Search**


- Updated to include sort by date (default), sort by name and sort order.
- You can change the sort setting in the first Python script under the "User Variables" commented section at the top. Instructions are in the comments.


This workflow will provide a search list dialogue for the current open document directory. You can scroll the list and select the file or use the search filter to narrow down the options. Selecting the filename will open the document.


This will not search the contents of the file. Files are sorted alphabetically. Trying to sort by date was much slower for a large number of files.


Hat tip to @macdrifter for the pointer to use os.stat for getting modified date cleaned up.

Shared by: @ryanlaner

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
Run Python Script ?
Source Code
#coding: utf-8
import editor
import os
import re
import sys
import workflow
import time

# User variables

sort_date = 1          # 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'])
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
Search Filenames
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Set Variable ?
Variable Name
TargetFilename
Value
Input
If… ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Show Alert ?
Title
No file selected
Message
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
Run Python Script ?
Source Code
#coding: utf-8
import editor
import os
import re
import sys
import workflow
from urllib import quote

# Set Variables
p = editor.get_path()
dir = os.path.split(p)[0]
openFile = workflow.get_variable('TargetFilename')

# Create editorial open URL from selected document
full_path = os.path.join(dir, openFile)
root, rel_path = editor.to_relative_path(full_path)
ed_url = 'editorial://open/' + quote(rel_path.encode('utf-8')) + '?root=' + root

workflow.set_output(ed_url)
Open URL ?
Open in
  • In-App Browser
  • Default App / Safari
URL
Input
Tab
  • Last-used Tab
  • New Tab
  • Tab with ID:
Unique identifier
Wait until Loaded
OFF
Reveal Browser Automatically
OFF