Editorial Workflows

Zotero Search

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 is a workflow-in-progress for searching your Zotero library and appending selected citations to a local BibTeX file (NOTE: workflow assumes you re using Dropbox).

You currently need to enter your Zotero UserID and API Key as parameters to the first Action. Create your Zotero API key here: http://www.zotero.org/settings/keys/new

Please report bugs to @mcburton on twitter. This is a BETA release.

Shared by: @mcburton

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Store Zotero Credentials ?
Set Variable ?
Variable Name
Bibliography Filename
Value
*.bib
Get Current Working Directory ?
Source Code
#coding: utf-8
import workflow
import editor
# Get the current file path
file_path = editor.get_path()
# remove filename to get path
current_dir = ''.join(file_path.rpartition('/')[0:2])
workflow.set_output(current_dir)
Set Variable ?
Variable Name
Current Working Directory
Value
Input
Get bibliography file list ?
Source Code
#coding: utf-8
import workflow
from glob import glob
import console

cwd_path = workflow.get_input()
bib_filename = workflow.get_variable("Bibliography Filename")
bib_path = ''.join([cwd_path, bib_filename]) 
bib_path = glob(bib_path) 

if not bib_path:
	console.hud_alert("No bibliography file(s) found. Using zotero.bib")
	bib_path = [cwd_path + "zotero.bib"]
	#workflow.stop()

action_out = '\n'.join(bib_path)
workflow.set_output(action_out)
Find / Replace ?
Find
Current Working Directory
  • Case-insensitive (A = a)
  • Case-sensitive (A ≠ a)
  • Regular Expression
Replace with
Set Variable ?
Variable Name
Bibliography Filename
Value
Input
Count ?
What to Count:
  • Words
  • Sentences
  • Lines
  • Characters
If… ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
1
Select from List ?
Title
Select Bibliography File
List (Lines)
File List
Multiple Selection
OFF
Show in Popover
OFF
Set Variable ?
Variable Name
Bibliography Filename
Value
Current Working DirectoryInput
…End If
Get Relative Directory Path ?
Source Code
#coding: utf-8
import workflow

# wish Editorial didn't make working with directories so difficult
bib_filename = workflow.get_variable('Bibliography Filename')
# Need the dropbox root, not local filesystem's root
current_dir  = workflow.get_variable('Current Working Directory').partition('Dropbox')[-1]
bib_file_path = current_dir + bib_filename
workflow.set_output(bib_file_path)
Set Variable ?
Variable Name
Relative Path
Value
Input
Request Text Input ?
Title
Zotero Search Query
Initial Text
  • Single Line
  • Multiple Lines
Keyboard Options:
Query Zotero ?
Parse Search Results ?
Source Code
#coding: utf-8
import workflow
import xml.etree.ElementTree as ET
import json

input = workflow.get_input()

#parse the ATOM response and load json content
#assumes well-formed content from Zotero
dom = ET.fromstring(input.encode('utf-8'))
rawCites = dom.findall('.//{http://www.w3.org/2005/Atom}content')
parsedCites= [json.loads(cite.text) for cite in rawCites]

def parseCite(cite):
	zkey = cite['itemKey'] #will aways have an item key
	title = cite['title'] # assuming there will be title
	try:
		# can't assume all name are broken into first/last
		author = cite['creators'][0]['lastName']
	except KeyError:
		# catch cites w/ one name field
		author = cite['creators'][0]['name']  
	except:
		# for everything else there's ?
		author = "?"
	return '-'.join([author, title, zkey])

titles = [parseCite(cite) for cite in parsedCites]
displayCites = '\n'.join(titles)
workflow.set_output(displayCites.strip())
Set Variable ?
Variable Name
Search Results
Value
Input
Count ?
What to Count:
  • Words
  • Sentences
  • Lines
  • Characters
If… ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
0
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
ON
Message
Search returned no results.
…End If
Generate Text ?
Text
Search Results
Sort Lines ?
Sort Order
  • Ascending (A → Z)
  • Descending (Z → A)
Select from List ?
Title
Select Citation
List (Lines)
Input
Multiple Selection
ON
Show in Popover
ON
Parse item keys ?
Source Code
#coding: utf-8
import workflow

selected_cites = workflow.get_input().split('\n')
zotero_itemKeys = [c[-8:] for c in selected_cites]
workflow.set_output(','.join(zotero_itemKeys))
Query Zotero ?
Parse Search Results ?
Source Code
#coding: utf-8
import workflow
import xml.etree.ElementTree as ET
import json
input = workflow.get_input()

dom = ET.fromstring(input.encode('utf-8'))
rawCites = dom.findall('.//{http://www.w3.org/2005/Atom}content')
bibtex_cites = ','.join([c.text for c in rawCites])
workflow.set_output(bibtex_cites)
Set Variable ?
Variable Name
New Cites
Value
Input
Get File Contents ?
File Name
%var:Relative Path
In Dropbox
ON
If File Does Not Exist
  • Empty Output
  • Stop Workflow
Generate Text ?
Text
Input,New Cites
Set File Contents ?
File Name
%var:Relative Path
In Dropbox
ON
New Text
Input
If File Does Not Exist
  • Create
  • Stop Workflow