giovannicoppola/zothero

How can I copy citekey in Better bibtex?

pkumath opened this issue · 16 comments

In the document it is said that we can set the variable "COPY SITEKEY MOD" to override other operations to get access to the better bibtex. But I tried to set it to cmd, ctrl, fn. It just does not work; it does not provide me with the cite key, but provides me with other formats which can not be used in "\cite{}".

After I did a naive change by exchanging the "copy-citation" and the "copy-citekey" position,
image
I got the following error report:
[10:59:02.919] ZotHero[Script Filter] Queuing argument 'an'
[10:59:03.049] ZotHero[Script Filter] Script with argv 'an' finished
[10:59:03.063] STDERR: ZotHero[Script Filter] .
10:59:03 workflow.py:2093 DEBUG ---------- ZotHero (2.0.1) ----------
10:59:03 zh.py:683 DEBUG args={'--bibliography': False,
'--help': False,
'--paste': False,
'--style': None,
'--text': None,
'--title': None,
'': None,
'': None,
'': None,
'': 'an',
'<style>': None,
'': None,
'attachments': False,
'citations': False,
'clear': False,
'config': False,
'copy': False,
'fields': False,
'locale': False,
'notify': False,
'reindex': False,
'search': True,
'setvar': False,
'style': False}
10:59:03 config.py:86 DEBUG [config] datadir='/Users/wengang/Zotero'
10:59:03 core.py:72 DEBUG [core] cachedir='/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero'
10:59:03 core.py:73 DEBUG [core] zotero_dir='
/Zotero'
10:59:03 core.py:74 DEBUG [core] attachments_dir=None
10:59:03 core.py:133 DEBUG [core] storage='/Zotero/storage'
10:59:03 core.py:134 DEBUG [core] styles='
/Zotero/styles'
10:59:03 cache.py:311 DEBUG [cache] opening store 'styles'...
10:59:03 cache.py:311 DEBUG [cache] opening store 'modtimes'...
10:59:03 zh.py:117 DEBUG Citation style: Chicago Manual of Style 17th edition (author-date)
10:59:03 zotero.py:206 DEBUG [zotero] database last modified 1.3 hours ago
10:59:03 index.py:202 DEBUG [index] last updated 1.3 hours ago
10:59:03 index.py:153 DEBUG [index] opened '/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero/search.sqlite'
10:59:03 index.py:271 DEBUG [index] up to date: '
/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero/search.sqlite'
10:59:03 zotero.py:206 DEBUG [zotero] database last modified 1.3 hours ago
10:59:03 index.py:202 DEBUG [index] last updated 1.3 hours ago
10:59:03 core.py:197 INFO [core] searching for "an" ...
10:59:03 index.py:245 INFO [index] 1 result(s) for 'an'
10:59:03 workflow.py:1483 DEBUG reading settings from /Users/wengang/Library/Application Support/Alfred/Workflow Data/giovanni-zothero/settings.json
10:59:03 workflow.py:2314 DEBUG set last run version: 2.0.1
10:59:03 workflow.py:2136 DEBUG ---------- finished in 0.036s ----------
[10:59:03.083] ZotHero[Script Filter] {
"items": [
{
"title": "An equivalence principle for the spectrum of random inner-product kernel matrices",
"subtitle": "Lu and Yau. 2022.",
"valid": true,
"arg": 1,
"uid": 1,
"variables": {
"action": "open-in-zotero",
"url": "zotero://select/items/1_KJIPB8N3",
"citekey": null,
"id": 1,
"stylename": "Chicago Manual of Style 17th edition (author-date)"
},
"text": {
"largetype": "An equivalence principle for the spectrum of random inner-product kernel matrices",
"copy": "zotero://select/items/1_KJIPB8N3"
},
"icon": {
"path": "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/lib/zothero/icons/written.png"
},
"mods": {
"cmd": {
"subtitle": "Copy citation (Chicago Manual of Style 17th edition (author-date))",
"variables": {
"action": "copy-citation",
"url": "zotero://select/items/1_KJIPB8N3",
"citekey": null,
"id": 1,
"stylename": "Chicago Manual of Style 17th edition (author-date)",
"style": "http://www.zotero.org/styles/chicago-author-date"
}
},
"alt": {
"subtitle": "Copy bibliography (Chicago Manual of Style 17th edition (author-date))",
"variables": {
"action": "copy-citation",
"url": "zotero://select/items/1_KJIPB8N3",
"citekey": null,
"id": 1,
"stylename": "Chicago Manual of Style 17th edition (author-date)",
"bibliography": "1",
"style": "http://www.zotero.org/styles/chicago-author-date"
}
},
"ctrl": {
"subtitle": "View all citation formats",
"variables": {
"action": "show-citations",
"url": "zotero://select/items/1_KJIPB8N3",
"citekey": null,
"id": 1,
"stylename": "Chicago Manual of Style 17th edition (author-date)"
}
},
"fn": {
"subtitle": "Open in Zotero",
"variables": {
"action": "open-in-zotero",
"url": "zotero://select/items/1_KJIPB8N3",
"citekey": null,
"id": 1,
"stylename": "Chicago Manual of Style 17th edition (author-date)"
}
},
"shift": {
"subtitle": "No attachments",
"valid": false,
"variables": {
"action": "open-in-zotero",
"url": "zotero://select/items/1_KJIPB8N3",
"citekey": null,
"id": 1,
"stylename": "Chicago Manual of Style 17th edition (author-date)"
}
}
}
}
]
}
[10:59:04.861] ZotHero[Script Filter] Processing complete
[10:59:04.870] ZotHero[Script Filter] Passing output '1' to Debug
[10:59:04.880] ZotHero[Debug] .
/----------- ZOT OUT -----------
query=1
variables={allvars}
-------------------------------/
[10:59:04.890] ZotHero[Debug] Processing complete
[10:59:04.899] ZotHero[Debug] Passing output '1' to Filter
[10:59:04.907] ZotHero[Debug] Passing output '1' to Filter
[10:59:04.915] ZotHero[Filter] Processing complete
[10:59:04.922] ZotHero[Filter] Passing output '1' to Call External Trigger
[10:59:04.929] ZotHero[External] Processing complete
[10:59:04.936] ZotHero[External] Passing output '' to Debug
[10:59:04.942] ZotHero[Debug] .
/------- COPY CITEKEY IN --------
query=
variables={allvars}
---------------------------------/
[10:59:04.948] ZotHero[Debug] Processing complete
[10:59:04.955] ZotHero[Debug] Passing output '' to Hide Alfred
[10:59:04.961] ZotHero[Hide Alfred] Processing complete
[10:59:04.967] ZotHero[Hide Alfred] Passing output '' to Run Script
[10:59:04.973] ZotHero[Debug] Passing output '1' to Filter
[10:59:04.979] ZotHero[Debug] Passing output '1' to Filter
[10:59:04.985] ZotHero[Debug] Passing output '1' to Filter
[10:59:05.025] STDERR: ZotHero[Run Script] .
10:59:04 workflow.py:2093 DEBUG ---------- ZotHero (2.0.1) ----------
10:59:04 zh.py:683 DEBUG args={'--bibliography': False,
'--help': False,
'--paste': False,
'--style': None,
'--text': None,
'--title': None,
'': '',
'': None,
'': None,
'': None,
'<style>': None,
'': None,
'attachments': False,
'citations': False,
'clear': False,
'config': False,
'copy': True,
'fields': False,
'locale': False,
'notify': False,
'reindex': False,
'search': False,
'setvar': False,
'style': False}
10:59:04 config.py:86 DEBUG [config] datadir='/Users/wengang/Zotero'
10:59:04 core.py:72 DEBUG [core] cachedir='/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero'
10:59:04 core.py:73 DEBUG [core] zotero_dir='
/Zotero'
10:59:04 core.py:74 DEBUG [core] attachments_dir=None
10:59:04 core.py:133 DEBUG [core] storage='/Zotero/storage'
10:59:04 core.py:134 DEBUG [core] styles='
/Zotero/styles'
10:59:04 zotero.py:206 DEBUG [zotero] database last modified 1.3 hours ago
10:59:04 index.py:202 DEBUG [index] last updated 1.3 hours ago
10:59:04 index.py:153 DEBUG [index] opened '/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero/search.sqlite'
10:59:04 index.py:271 DEBUG [index] up to date: '
/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero/search.sqlite'
10:59:04 cache.py:311 DEBUG [cache] opening store 'styles'...
10:59:04 cache.py:311 DEBUG [cache] opening store 'modtimes'...
10:59:04 workflow.py:2114 ERROR key must be str or unicode, not NoneType
Traceback (most recent call last):
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/lib/workflow/workflow.py", line 2107, in run
func(self)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/zh.py", line 717, in main
return do_copy(args['<style>'], entry_id, args['--bibliography'],
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/zh.py", line 349, in do_copy
s = app.style(style_key)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/lib/zothero/core.py", line 202, in style
return self.styles.get(key)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/lib/zothero/styles.py", line 148, in get
return self.store.get(key)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/lib/zothero/cache.py", line 132, in get
key = self._validate_key(key)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.9A8F9B84-7339-4192-A9EC-29BA0B510DDF/lib/zothero/cache.py", line 245, in _validate_key
raise TypeError(
TypeError: key must be str or unicode, not NoneType
10:59:04 workflow.py:2116 INFO for assistance, see: https://github.com/giovannicoppola/zothero/issues
10:59:04 workflow.py:2136 DEBUG ---------- finished in 0.031s ----------

you are correct @pkumath, the citekey part appears to be broken. I have never used it, let me look into it.

you are correct @pkumath, the citekey part appears to be broken. I have never used it, let me look into it.

Thank you very much! Looking forward to using it. Excited to find this repo! Please tell me if you need any more information or help.

@pkumath could you try this version?

Thank you for your efforts! However, this version does not work at all. This is the error report:
image

[10:15:11.508] Logging Started...
[10:15:14.003] ZotHero[Script Filter] Queuing argument 'an'
[10:15:19.430] ZotHero[Script Filter] Script with argv 'an' finished
[10:15:19.435] STDERR: ZotHero[Script Filter] .
10:15:14 workflow.py:2093 DEBUG ---------- ZotHero (2.1.0) ----------
10:15:14 zh.py:684 DEBUG args={'--bibliography': False,
'--help': False,
'--paste': False,
'--style': None,
'--text': None,
'--title': None,
'': None,
'': None,
'': None,
'': 'an',
'<style>': None,
'': None,
'attachments': False,
'citations': False,
'clear': False,
'config': False,
'copy': False,
'fields': False,
'locale': False,
'notify': False,
'reindex': False,
'search': True,
'setvar': False,
'style': False}
10:15:14 config.py:86 DEBUG [config] datadir='/Users/wengang/Zotero'
10:15:14 core.py:72 DEBUG [core] cachedir='/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero'
10:15:14 core.py:73 DEBUG [core] zotero_dir='
/Zotero'
10:15:14 core.py:74 DEBUG [core] attachments_dir=None
10:15:14 core.py:133 DEBUG [core] storage='/Zotero/storage'
10:15:14 core.py:134 DEBUG [core] styles='
/Zotero/styles'
10:15:14 cache.py:311 DEBUG [cache] opening store 'styles'...
10:15:14 cache.py:311 DEBUG [cache] opening store 'modtimes'...
10:15:14 zh.py:117 DEBUG Citation style: Chicago Manual of Style 17th edition (author-date)
10:15:14 zotero.py:213 DEBUG [zotero] database last modified 2.9 mins ago
10:15:14 index.py:202 DEBUG [index] last updated 2.8 mins ago
10:15:14 index.py:153 DEBUG [index] opened '/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero/search.sqlite'
10:15:14 index.py:301 DEBUG [index] updating '
/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero/search.sqlite' ...
10:15:14 zotero.py:190 DEBUG [zotero] opened database '~/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/giovanni-zothero/zotero.sqlite'
10:15:14 zotero.py:308 DEBUG [zotero] + "An equivalence principle for the spectrum of random inner-product kernel matrices"
10:15:14 zotero.py:360 DEBUG [zotero] attachment={'key': 'VPBHE48S', 'name': 'Full Text', 'path': '/Users/wengang/Zotero/storage/VPBHE48S/Lu and Yau - 2022 - An equivalence principle for the spectrum of rando.pdf', 'url': 'https://arxiv.org/pdf/2205.06308.pdf'}
10:15:19 workflow.py:2114 ERROR database is locked
Traceback (most recent call last):
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/workflow/workflow.py", line 2107, in run
func(self)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/zh.py", line 734, in main
return do_search(query)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/zh.py", line 130, in do_search
if app.stale and not running:
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/core.py", line 159, in stale
if self.index.empty:
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/core.py", line 152, in index
self._index.update(self.zotero)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/index.py", line 277, in update
if not self._update(zot, force):
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/index.py", line 325, in _update
for e in it:
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/zotero.py", line 280, in all_entries
yield self._load_entry(row)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/zotero.py", line 332, in load_entry
e.citekey = self.bbt.citekey('{}
{}'.format(e.library, e.key))
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/zotero.py", line 202, in bbt
self._bbt = BetterBibTex(self.datadir)
File "/Users/wengang/Documents/Alfred.alfredpreferences/workflows/user.workflow.40A6A193-794C-4954-AF8C-F7EB54615D47/lib/zothero/betterbibtex.py", line 53, in init
row = conn.execute(SQL).fetchone()
sqlite3.OperationalError: database is locked
10:15:19 workflow.py:2116 INFO for assistance, see: https://github.com/giovannicoppola/zothero/issues
10:15:19 workflow.py:2136 DEBUG ---------- finished in 5.320s ----------
[10:15:19.439] ZotHero[Script Filter] {
"items": [
{
"title": "Error in workflow 'ZotHero'",
"subtitle": "database is locked",
"valid": false,
"icon": {
"path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
}
}
]
}

@pkumath could you try this version?

Moreover, I did not see this situation in the previous workflow. It seems like to be a new error.

oh, that's because Zotero needs to be closed while the database gets rebuilt. Close Zotero

oh, that's because Zotero needs to be closed while the database gets rebuilt. Close Zotero

Well, I did as you said, but some strange things happened.

Whenever I open my zotero, I get this error report:
image

But if I close my zotero, it works.
image

Then I rebuild the zotHero database but zotconfig. Then I reopen zotero, it still does not work.
image

What happened here? Do I need to reinstall all of these things?
Moreover, for this new version, when I press "enter", it will give me an empty zotero, which is quite strange.
image

But I think it is necessary to work with zotero openning... lol

Can you tell me what's going wrong here?

Here is the whole log file.
https://www.dropbox.com/s/4l9p61vg82tgeat/giovanni-zothero.log?dl=0

oh, that's because Zotero needs to be closed while the database gets rebuilt. Close Zotero

I just tried to reinstall this workflow and zotero, but it could not fix this issue.

I see what is happening. the workflow creates copies of the other tables, but not the citekey table. I don't think this feature ever worked properly even in Python 2. I will fix this. In the meantime, you can either use the old version (with citekey not working) or the new version, while Zotero is closed. Thanks for your help with troubleshooting!

I see what is happening. the workflow creates copies of the other tables, but not the citekey table. I don't think this feature ever worked properly even in Python 2. I will fix this. In the meantime, you can either use the old version (with citekey not working) or the new version, while Zotero is closed. Thanks for your help with troubleshooting!

Many thanks! Can't wait for the next version. 😊 If I were able to understand those complex codes, I would also work with you lol (however I was not familiar with coding)

could you try again?

Sure, I just tried. It works! The only small problem is that if you do not open zotero and try to open zotero by press "enter", you still get the empty zotero like this:
image
But if you have already opened zotero, it will jump to the correct index. I think this issue is negligible, just report this finding lol.

Alright, I think it is currently OK for me! I will report issues again if I find any. Thank you very much!!!

The only small problem is that if you do not open zotero and try to open zotero by press "enter", you still get the empty zotero

did it not do that before?

The only small problem is that if you do not open zotero and try to open zotero by press "enter", you still get the empty zotero

did it not do that before?

Ah, I am a little confused. What do you mean by "before"? My precise meaning is that it does not work in all these versions, including the original one; since it is not the most important problem (at least for me), so I did not report it at first. I reported it with the log file just because I thought it might have some connections with this issue topic.

yes I was trying to figure out if I introduced this issue with my recent changes, or if it was there from before. It sounds like it has always been there, so I will close this issue for now. Thanks!