Skip to content

Instantly share code, notes, and snippets.

@mcburton
Created February 11, 2014 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcburton/8929332 to your computer and use it in GitHub Desktop.
Save mcburton/8929332 to your computer and use it in GitHub Desktop.
To Install(I think, I haven't tested it): Copy the text to the clipboard, then create a new workflow and select "Paste Workflow" from the share button in the upper right. This is a rough first cut at an Editorial workflow that can parse a bibtex file, generate a list of citekeys, and prompt the user about which to insert. NOTE: you need to make …
------------ BEGIN WORKFLOW ------------
{
"actions" : [
{
"class" : "WorkflowActionGetFileName",
"pauseBeforeRunning" : false,
"customTitle" : "",
"parameters" : {
"includeExtension" : true,
"includeFolder" : false
},
"pauseWithoutShowingParameters" : false
},
{
"class" : "WorkflowActionRunScript",
"pauseBeforeRunning" : false,
"customTitle" : "Get bib file path",
"parameters" : {
"script" : "#coding: utf-8\nimport workflow\nimport glob\nimport editor\nimport console\n\n\ncurrent_filename = workflow.get_input()\ncurrent_path = editor.get_path()\ncurrent_dir = current_path.replace(current_filename,\"\")\nbib_path = ''.join([current_dir, \"*.bib\"])\nbib_files = glob.glob(bib_path)\n\nif len(bib_files) > 1:\n\tconsole.alert(\"More than one .bib files, picking %s\" % bib_files[0])\n\nworkflow.set_output(bib_files[0])\n"
},
"pauseWithoutShowingParameters" : false
},
{
"class" : "WorkflowActionRunScript",
"pauseBeforeRunning" : false,
"customTitle" : "Parse out citekeys",
"parameters" : {
"script" : "import workflow\nbibtex_filename = workflow.get_input() # expects bibtex file path as input\nwith open(bibtex_filename, 'r') as bib_file: # open the file\n\tcitekeys = \"\".join([line.split(\"{\")[1].replace(\",\",\"\") for line in bib_file if line.startswith(\"@\")]) # parse out the citekeys then make newline deliminated string\nworkflow.set_output(citekeys) #output newline string\n"
},
"pauseWithoutShowingParameters" : false
},
{
"class" : "WorkflowActionSelectFromList",
"pauseBeforeRunning" : false,
"customTitle" : "prompt for citekey",
"parameters" : {
"title" : "Select Citation",
"allowMultipleSelection" : false,
"showInPopover" : false,
"list" : {
"tokenRanges" : {
"{0, 1}" : "Input"
},
"type" : "advancedText",
"text" : "?"
}
},
"pauseWithoutShowingParameters" : false
},
{
"class" : "WorkflowActionFormatString",
"pauseBeforeRunning" : false,
"customTitle" : "",
"parameters" : {
"text" : {
"tokenRanges" : {
"{2, 1}" : "Input"
},
"type" : "advancedText",
"text" : "[@?]"
}
},
"pauseWithoutShowingParameters" : false
},
{
"class" : "WorkflowActionReplaceSelectedText",
"pauseBeforeRunning" : false,
"customTitle" : "",
"parameters" : {
"replacement" : {
"tokenRanges" : {
"{0, 1}" : "Input"
},
"type" : "advancedText",
"text" : "?"
}
},
"pauseWithoutShowingParameters" : false
}
],
"name" : "bibtex"
}
------------- END WORKFLOW -------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment