Jump to content
smarg19

ZotQuery: an Alfred workflow for Zotero

Recommended Posts

This workflow is dead. Please check out its spiritual replacement ZotHero instead.

 

ZotQuery

Search Your Zotero Data From the Comfort of Your Keyboard.

 

Please update (via Packal) to Version 8.5, for optimal performance. 

ZotQuery_logo.png

ZotQuery is an Alfred workflow that grants the user access to the data stored in their Zotero application. The Python scripts in this repo form all of the necessary components for this workflow.

To download, visit the page on Packal, the workflow aggregator for Alfred, where you will be able to update to the newest versions.

 

For a full README, filled with images (the forums limit you), visit my blog at: http://hackademic.postach.io/zotquery-an-alfred-workflow-for-zotero

Unfortunately, there are too many features and too many screenshots for this forum to handle. But the page on my blog has extensive documentation.

 

I've just pushed another update to Packal (v. 8.0.3). Please update if you have an older version.

 

In version 6.2, "odt-scannable-cites" is a new option in the z:set export options. If you export a full Citation or a short Reference, you will get a base form Scannable Cite for that item.

 

Version 6.0 moves the backbone of the workflow from alp to @deanishe's Workflow library, which among other things, allows for a new debugging keyword. Now, if user's wish to report an error, they can use z:bug to automatically open ZotQuery's log file, which you should include alongside your error report in this thread.. In addition, version 6.0 adds new, shorter script filter keywords. I've kept all of the old, longer keywords as well, so everything is backwards compatible, but now, users can simply use:

  • z = zot
  • zt = zot:t
  • za = zot:a
  • znc = zot:c
  • znt = zot:tag
  • zn = zot:n
  • zat = z:att
  • ztg = z:tag
  • zc = z:col

Unfortunately, version 6.0 also removes version 5.0's ability to add a PDF attachment to an item in your Zotero library. However, this and other PDF management features are under development, and I will push out an update that brings this back (with more) sooner rather than later.

 

All of this comes in addition to the big additions from 4.0:

  • ZotQuery now can export in both Markdown and Rich Text. This means all academics on the Mac who use Zotero can take advantage of ZotQuery's quick access to their citation data. Export individual references or citations in rich text, or export full bibliographies from Collections or Tags in rich text.
  • Exporting preferences to the configurator. Now you can select out of 5 possible CSL styles for export. Instead of the default Chicago (author-date), you can now also choose APA, MLA, BibTeX, or Zotero's own RTF-Scan cite key format. In addition, you will also then choose which format to export in: Markdown or Rich Text. At any point, you can also change these settings using the z:settings command.
  • Ability to search only items with attachments. This works effectively like an attachments search, since you only need to press return (not shift+return as with the other queries) in order to open the attachment.

The ability now to export in BibTeX or Zotero's RTF-Scan format makes ZotQuery is utility for LaTeX writers as well as scholars who write in standard word processors. You could also easily move from BibTeX or RTF-Scan and take advantage of ZotQuery's full text exporting in Markdown or Rich Text. Either way, the workflow should be a helpful companion regardless of your writing workflow. 

 

These features are in addition to the standard features of ZotQuery:

  • Search your Zotero library with keyword
  • Search by author last name, title, in collection, or in tag
  • Open, export short reference, export full citation, or append citation to temporary bibliography[/[/i]]
  • Export full bibliography from collection or tag in alphabetical order
  • Create and keep up-to-date a JSON cache of your Zotero data (helpful for other scripting possibilities)

As a side-note, can people let me know what version of OS X you have ZotQuery working on? And what your Zotero set-up is? (Standalone? Firefox? Both?). I want to upgrade my README with testing conditions. Any info is helpful. Thank you.

 

I hope you enjoy it.

-stephen

Edited by deanishe
Add notice on workflow status and point to ZotHero instead

Share this post


Link to post
A quick update:

 

I've added a feature to append Markdown citations to a bibliography text file, which you can export to the clipboard (keyword "z:bib") at any point. The bibliography will automatically be sorted alphabetically and have a WORKS CITED header. 

 

To append a reference (rather than simply copying it to the clipboard) use "fn+return". The sub-title field will change with a description of the action. 

 

These changes have been made in the download version and more details are in the README at the GitHub page.

Edited by smarg19

Share this post


Link to post

Second update:

 

You can now export all of the items in a particular Collection or Tag as a Markdown-formatted bibliography (defaults to Chicago (author-date) style). 

After you select either a Collection or a Tag after a z:tag or z:col, you have 2 options:

  1. You can search within that Tag or Collection.
  2. You can export a Markdown-formatted bibliography of all the items within that Tag or Collection

  • To simply search within that Tag or Collection for a particular item, hit return.
  • To export a Bibliography, hit control+return. When you hold down control, the subtitle of the item will change, letting you know that you have a different option.

export_bib_screenshot.png

The exported Bibliography will be formatted in Markdown, and like the appended bibliography, it will automatically be alphabetically ordered and have a WORKS CITED header. A notification will let you know when the bibliography has been copied to the clipboard:

copy_screenshot.png

TIP: This feature comes in handy if you use either Collections or Tags to organize citations for particular writing projects. Once you feel you have all of the citations for a particular paper stored within a Collection or Tag, ZotQuery can create you bibliography for you. Using this feature in tandem with the Export Reference feature, you can easily generate and insert individual references and whole bibliographies into your papers.

For reference, here's what a Markdown bibliography in Chicago (author-date) style would look like:

WORKS_CITED.png

Share this post


Link to post

2nd major upgrade:

 

You can now open attachments from ZotQuery. 

 

Items with attachments will have the number of attachments displayed in the Subtitle field. To open an attachment, use `shift+return`.

Share this post


Link to post

Hi
I'm very excited to see the arrival of this workflow. I've been checking this forum for a Zotero Workflow ever since I activated the PowerPack; one of the first things I checked for, so thank you very, very much for the time and effort you've put into this. However, I've followed your very well presented instructions and have not been able to get ZotQuery to communicate with my Zotero account. After I select one of the query options (General Query, for example), Alfred returns a fallback search as soon as I input a search term. Any suggestions? I can't thank you enough for making this, I spend hours upon hours in Zotero and I'm very much looking forward to trying this out.

Share this post


Link to post

Was hoping for this for a long while – Zotero and Alfred are in daily use here and having them work together with ZotQuery is very exciting. Thanks for making this possible! Like culb0743 above I've installed and customized the .json (with Coda in my case) and have the same results: upon invoking Alfred, typing "Zot" and selecting the ZotQuery options (anyone) I get the fallback search as soon as I start tyiping a search string (Google, Amazon, Wikipedia). Rifled through my workflows to see whether one of them interferes but found nothing obivous. Could't see an obvious Alfred option to disable either. Any ideas? Looking forward to more of this – thanks.

Edited by kithairon

Share this post


Link to post

@kithairon and @culb0743,

 

I'm sorry for any issues. Here are a few ideas:

 

I've updated the workflow a number of times, so I would delete and re-install first and see if this helps.

 

If not, I tried to put in a lot of logging in the workflow to make for easier debugging. If the re-install doesn't help, open the workflow folder, find the debug log and shoot me a picture of what it has. 

 

Also, how have you altered the JSON? All of the queries read against the JSON, so if its altered in such a way that the queries don't understand it (if you change key names for instance), then that would also mess it up. 

 

I'm happy to help, so let me know how these suggestions work.

 

stephen

Share this post


Link to post

Also, you will need to generate the cache file before you can search. So, once you download the workflow, you will need to run `z:cache` first and let it cache your Zotero data, then start running queries and the workflow will auto-update the cache from then on (tho you can always force update the cache).

Share this post


Link to post

One final thing, in the newest version of the workflow, I've added an output.log for all scripted parts of the workflow. This is in tandem with the debug.log that a number of the script log to as well. So, if you have an error, please do open the workflow folder and send me the details of both of those logs, as that will greatly help me in debugging/fixing the issue. 

Share this post


Link to post

smarg19,

 

Thank You for all of the time and effort you are putting into this. So far, I've deleted the ZotQuery workflow I installed initially, re-downloaded the workflow, and reinstalled. I altered the .json according to your instructions and ran z;cache before initializing a Zotero database query through Alfred. Alas, I'm experiencing the same behavior I and kitharion described yesterday. However, I have some screenshots of the ZotQuery output log, the errors Alfred reported to my console, and the .json file as I altered it. At the moment, I cannot  figure out how to attach images to this forum post, so I'll attempt to get the screenshots posted as soon as I find out how. 

Share this post


Link to post

I think I just pasted the images in, but I'm not really certain how to properly embed images either. If you don't have it figured out tomrrow, you can just copy and paste the text.

Share this post


Link to post

Thanks for your suggestions Stephen. I've reinstalled your workflow, altered the .json, run z:cache (that one I left out last time) However, the results are the same as before: the fallback search kicks in as soon as I enter a string. Here the screenshot of settings and logs – I'm grateful that you're putting your heart into this workflow.

 

DEbug.log:

 

[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Error! Could not find database in Profile path. (2014-01-10-14:51:58)]
[com.hackademic.zotquery: Database Success! Completed backup of Zotero database. (2014-01-10-14:52:01)]
[com.hackademic.zotquery: Collections Success! Completed json backup of Zotero collections data. (2014-01-10-14:52:01)]
[com.hackademic.zotquery: Tags Success! Completed json backup of Zotero tags data. (2014-01-10-14:52:01)]
[com.hackademic.zotquery: Attachements Success! Completed backup of Zotero attachment data. (2014-01-10-14:52:01)]
[com.hackademic.zotquery: Final Success! Created JSON cache of Zotero database. (2014-01-10-14:52:01)]
[com.hackademic.zotquery: Database Success! Completed backup of Zotero database. (2014-01-10-14:52:41)]
[com.hackademic.zotquery: Collections Success! Completed json backup of Zotero collections data. (2014-01-10-14:52:41)]
[com.hackademic.zotquery: Tags Success! Completed json backup of Zotero tags data. (2014-01-10-14:52:41)]
[com.hackademic.zotquery: Attachements Success! Completed backup of Zotero attachment data. (2014-01-10-14:52:41)]
[com.hackademic.zotquery: Final Success! Created JSON cache of Zotero database. (2014-01-10-14:52:41)]
[com.hackademic.zotquery: Update Cache process begin. (2014-01-10-14:55:19)]
[com.hackademic.zotquery: Database Success! Completed backup of Zotero database. (2014-01-10-14:55:22)]
[com.hackademic.zotquery: Collections Success! Completed json backup of Zotero collections data. (2014-01-10-14:55:22)]
[com.hackademic.zotquery: Tags Success! Completed json backup of Zotero tags data. (2014-01-10-14:55:22)]
[com.hackademic.zotquery: Attachements Success! Completed backup of Zotero attachment data. (2014-01-10-14:55:22)]
[com.hackademic.zotquery: Final Success! Created JSON cache of Zotero database. (2014-01-10-14:55:22)]
[com.hackademic.zotquery: Update Cache process begin. (2014-01-10-14:56:16)]
[com.hackademic.zotquery: Database Success! Completed backup of Zotero database. (2014-01-10-14:56:19)]
[com.hackademic.zotquery: Collections Success! Completed json backup of Zotero collections data. (2014-01-10-14:56:19)]
[com.hackademic.zotquery: Tags Success! Completed json backup of Zotero tags data. (2014-01-10-14:56:19)]
[com.hackademic.zotquery: Attachements Success! Completed backup of Zotero attachment data. (2014-01-10-14:56:19)]
[com.hackademic.zotquery: Final Success! Created JSON cache of Zotero database. (2014-01-10-14:56:19)]
[com.hackademic.zotquery: START: update cache process. (2014-01-10-14:57:42)]
[com.hackademic.zotquery: Database Success! Completed backup of Zotero database. (2014-01-10-14:57:44)]
[com.hackademic.zotquery: Collections Success! Completed json backup of Zotero collections data. (2014-01-10-14:57:44)]
[com.hackademic.zotquery: Tags Success! Completed json backup of Zotero tags data. (2014-01-10-14:57:44)]
[com.hackademic.zotquery: Attachements Success! Completed backup of Zotero attachment data. (2014-01-10-14:57:44)]
[com.hackademic.zotquery: Final Success! Created JSON cache of Zotero database. (2014-01-10-14:57:44)]
[com.hackademic.zotquery: END: update cache process. (2014-01-10-14:57:44)]
 

 

Output.log:

Traceback (most recent call last):
  File "action_update-caches.py", line 3, in <module>
    from dependencies import alp
  File "/Users/amw/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/user.workflow.3A81FB7B-D19E-4290-AFA2-3068CBE4B76D/dependencies/alp/__init__.py", line 1, in <module>
    from .core import *
  File "/Users/amw/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/user.workflow.3A81FB7B-D19E-4290-AFA2-3068CBE4B76D/dependencies/alp/core.py", line 12, in <module>
    from .core_dependencies import biplist
  File "/Users/amw/Backup/AlfredSettings/Alfred.alfredpreferences/workflows/user.workflow.3A81FB7B-D19E-4290-AFA2-3068CBE4B76D/dependencies/alp/core_dependencies/biplist/__init__.py", line 57, in <module>
    import alp.core_dependencies.six as six
ImportError: No module named alp.core_dependencies.six
 

(Can't seem to post a screenshot here. "You are not allowed to use that image extension here" irrespective of the three different extension I tried).

Share this post


Link to post

Ok. This is alot of helpful information, thank you. The problem for both of you lies in the alp module. Both errors claim that they cannot find the `alp.core_dependencies.six` script. This is odd. Could you open your workflow folder, open the dependencies folder, then the alp folder, then core_dependencies and tell me what's there. This is where the `six.py` script should reside, but the error says it can't find it there. 

 

If the script is there, I will need to dig some more to figure out why it's not being picked up. Could you tell me what version of OS X you're running and can you find out what version of Python you have (open Terminal and enter `python` then hit return)? 

Share this post


Link to post

Note, in dependencies/alp/core_dependencies, there should be at least three things: a folder called biplist, a scipt called __init__.py, and a script called six.py. Let me know if all three are there.

Share this post


Link to post

I've exceeded my 10 per day CloudApp uploads (which is the only way I've figured out to share a ss), so here are some links to screenshots of the folders, files, and version of Python in question. Running OSX 10.9.1. Again, thank you for putting so much into this workflow. I'm certain that it will add much, much appreciated functionality to the research/ composition habits of many students. Mac Users have often played second fiddle to Windows Users when it comes to Zotero add ons/ plugins/ extensions. I can't wait to share with others in the Zotero Community Forums. 

 

https://www.dropbox.com/s/qakspfr71nrzar1/Dependencies.png

 

https://www.dropbox.com/s/2jztm22uqjh3k3o/sixpy.png

 

https://www.dropbox.com/s/r2sgxz0rlnbqzaf/python.png

Edited by culb0743

Share this post


Link to post

Ok. I have uploaded a new version of the workflow that I believe will fix the problem. Please go re-install. 

 

For posterity's sake, I will briefly explain the issue. In short, I made a rookie mistake (which makes sense, since I'm a Python rookie). I like organization, so I wanted to put all of the code's dependencies and modules within a sub-directory in the workflow folder. So I put the alp module, the pyzotero module, the applescript script, and the html2md scripts in there. At various points in the workflow all of these scripts and modules are called, but none of this is my code. Well, I didn't fully understand (and still don't *fully*) how Python treats scripts that are imported in other scripts. When I was importing the alp module, my local workflow was actual importing the alp module that I have download to my PATH (/Library/Python/2.7/site-packages), not the alp module within the dependencies directory. This was allowing my local workflow to function properly. BUT, for those of you (most of you I would imagine) who don't have the alp module within your system, the import call could only find the module in the dependencies directory. Well, for Python, nesting modules and such is not exactly the same as nesting directories in the file system. Your "folders" need to be properly configured Packages, not simply directories. So by putting alp within the dependencies folder, I was actually putting it within a Python Package without knowing it, and thus without configuring the dependencies directory accordingly. This is probably rambling at this point, and I'm not even 100% clear on all of this, but the short point is, I've fixed it (I believe).

 

I have also deleted these modules from my PATH, so that I can better debug the average user's problems. I'm sorry for the issues, but thanks a ton to @culb0743 and @kithairon for bringing this major bug to light. 

 

Please let me know if this fixes your problems.

 

stephen

Share this post


Link to post

P.S. 

 

Mac Users have often played second fiddle to Windows Users when it comes to Zotero add ons/ plugins/ extensions. I can't wait to share with others in the Zotero Community Forums. 

 

I totally agree, and for me, this is a souped-up Mac version of Qnotero. Having quick access to my library of citations is massively important to me, and with the added bonus of various Export options and now opening attachments, this workflow is easily the most helpful thing I've ever made. Though, I have made a few other things for academics on the Mac. If you're interested, I've been blogging (less recently) at Hackademic and I keep a collection of Applescripts on my Gists page. I have a lot of applescripts for Evernote and Skim. I'm actually currently working on putting my favorites in a bundle on GitHub. But if you read a lot of PDFs or use Evernote, you might find something helpful there as well.

Share this post


Link to post

Thanks for looking into this. Deleted my previous post since I responded before your latest update. I have still the same results: Here the output.log's message:

Traceback (most recent call last):
  File "filter_zot-general.py", line 14, in <module>
    json_data = open(cache, 'r')
IOError: [Errno 2] No such file or directory: '/Users/amw/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/com.hackademic.zotquery/zotero_db.json'
 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×