giovannicoppola / zothero

Rapidly search and cite Zotero entries from Alfred
MIT License
119 stars 9 forks source link

change zotero://select/items/key to zotero://open-pdf/library/items/key #30

Closed ljci closed 2 days ago

ljci commented 7 months ago

Hi I just want to modify the zotero://select/items/key to zotero://open-pdf/library/items/key so that I can open PDF in Zotero with zot file_name, not only select the file in zotero but open them in zotero?

I do modified the code in zh.py and remove the prefix "1_" but I fount the "key" which is index code in alfred workflow deubgger is different from the real index code in zotero. Be more specifically, the index code in zotero is something like 7SDEUXN, while the index code with removed prefix in alfred workflow is something SOEJ2DS, which doesn't match.

So I am wondering how you index the index code from zotero Thank you

zrfisher commented 6 months ago

Add this function above do_search

def get_pdf_id(e):
    if not e:
        return None

    if not e.attachments:
        return None

    atts = e.attachments[:]
    pdf_ids = []
    for att in atts:
        if att.path and att.path[-4:] == ".pdf":
            pdf_ids.append(att.key)

    if len(pdf_ids) == 1:
        return pdf_ids[0]
    else:
        return None

change the url line to


pdf_key = get_pdf_id(e)
url = u'zotero://open-pdf/library/items/' + pdf_key if pdf_key else u'zotero://select/items/' + key```