Skip to content

Instantly share code, notes, and snippets.

@driscoll
Created September 23, 2025 14:53
Show Gist options
  • Select an option

  • Save driscoll/dfa86c8978bfae74cae8747d5545f513 to your computer and use it in GitHub Desktop.

Select an option

Save driscoll/dfa86c8978bfae74cae8747d5545f513 to your computer and use it in GitHub Desktop.
Send highlighted text to ZoteroBib with AutoHotkey
; URL encoding helpers
; Cribbed from the ahk forums
UriEncode(Url, Flags := 0x000C3000) {
Local CC := 4096, Esc := "", Result := ""
Loop
VarSetStrCapacity(&Esc, CC), Result := DllCall("Shlwapi.dll\UrlEscapeW", "Str", Url, "Str", &Esc, "UIntP", &CC, "UInt", Flags, "UInt")
Until Result != 0x80004003 ; E_POINTER
Return Esc
}
UrlUnescape(Url, Flags := 0x00140000) {
Return !DllCall("Shlwapi.dll\UrlUnescape", "Ptr", StrPtr(Url), "Ptr", 0, "UInt", 0, "UInt", Flags, "UInt") ? Url : ""
}
; Hotkey to import highlighted text to ZoteroBib (Alt+Shift+B)
+!b::
{
; Store the original clipboard content
originalClipboard := A_Clipboard
; Copy the selected text
Send("^c")
Sleep(200) ; Brief pause to ensure copy completes
; Retrieve the copied text
copiedText := A_Clipboard
; Construct ZoteroBib import URL with URL-encoded text
zoteroImportURL := "https://zbib.org/import?q=" . UriEncode(copiedText)
; Open in default browser
Run(zoteroImportURL)
; Restore the original clipboard content
A_Clipboard := originalClipboard
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment