Autohotkey script for entering tags in PC client

edited May 5, 2017
I've developed the following AutoHotkey script for entering tags in the Zotero Standalone client for Windows. When you press the hotkey (Windows key + z but you can change it in the script) it reads a text file you create of your tags, sorts them alphabetically, and allows you to jump to the tag of choice by pressing the letter key it begins with. For example, if your file had the tags:

Goodbye
Heaven
Heavy
Hello
Walmart

each time you pressed H it would jump to the next word that begins with H.

The hotkey is only active when the Zotero client is the active window; otherwise the hotkey is ignored, so if you use the hotkey for another purpose elsewhere, it should work fine.

As explained in the script comments, you have to leave your mouse over the Add button while selecting the tag with the keyboard. Eliminating that restriction would make it more user-friendly, but also dependent on screen resolution, and I wanted to avoid that.

It requires having AutoHotkey installed on your computer. I could compile it so that it runs without AutoHotkey if anyone wants that, but at that point you no longer have control over which keystrokes trigger it, and where you place your tags file. You can download AutoHotkey here:

https://autohotkey.com/

It's not the most elegant solution, but it should work on any PC, and I've found I can enter tags a lot faster than with the Zotero interface.

I can't promise a lot of support, but will respond to questions as best I can.

AHK Script:

; This script reads and sorts a text file of my Zotero tags, creates a popup menu of them, and adds the selected tag to the item in Zotero; the cursor must remain over the Add button in the Tags dialog. It has to stay there, so you can't use the mouse to select the tag, you have to use the arrow keys or the letter keys to jump to the words that start with the letter you type. Then when you activate the hotkey, it gives you the menu, then when you select a menu option it clicks the Add button and pastes the selected item in the entry box that opened when you clicked the Add button
;
; Every time you execute the script it reads the file, sorts it, deletes the file, then writes it again. That way you can add tags to the file any time you want, and you don't have to worry about sorting them.
;
; To use this script, create a file named Zotero Tags.txt. I have it stored in the folder:
; J:\Dropbox\Files Shared Across Computers\
; You can store it wherever you want, just change all references to my folder to reference your folder. You can also use a different file name if you want.
;
; I can't promise a lot of support for this, but feel free to contact me if you have questions and I'll do what I can. My email is tgsupport@iks-inc.com.
;
; The hotkey is set to Windows key + z; you can change it to anything you like.

#IfWinActive, ahk_exe zotero.exe ; only execute if Zotero is running
#z:: ;use Windows key + Z
; The following sorts the contents of the file:
FileRead, Contents, J:\Dropbox\Files Shared Across Computers\Zotero Tags.txt
if not ErrorLevel ; Successfully loaded.
{
Sort, Contents
FileDelete, J:\Dropbox\Files Shared Across Computers\Zotero Tags.txt
FileAppend, %Contents%, J:\Dropbox\Files Shared Across Computers\Zotero Tags.txt
Contents = ; Free the memory.
}
Loop, Read, J:\Dropbox\Files Shared Across Computers\Zotero Tags.txt ;now create the menu and call the menu handler
Menu, TagsMenu, Add, %A_LoopReadLine%, MenuHandler
Menu, TagsMenu, Show
Menu, TagsMenu,DeleteAll ; this clears out the old menu contents so it can repopulate with the new ones
return ; this is also required...

MenuHandler:
Click Left ; The cursor should be left sitting over the Add buton in the Tags dialog; Click Left then clicks the Add button
Send %A_ThisMenuItem% {Enter} ; send the selected item to the entry box that opened when you clicked the Add button
return
Sign In or Register to comment.