Skip to content

Instantly share code, notes, and snippets.

@mykappa
Created April 14, 2023 08:36
Show Gist options
  • Save mykappa/715fc22d5def9ac842996aaf51833910 to your computer and use it in GitHub Desktop.
Save mykappa/715fc22d5def9ac842996aaf51833910 to your computer and use it in GitHub Desktop.
Use AutoHotkey to remove unwanted characters like line breaks from the clipboard when copying text from a PDF with ctrl+c (tested with Adobe Acrobat and SumatraPDF)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive ahk_class SUMATRA_PDF_FRAME
^c::
old := ClipboardAll
clipboard := ""
send ^c
clipwait 0.1
if clipboard =
clipboard := old
else {
tmp := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2")
clipboard := tmp
StringReplace clipboard, clipboard, % " ", % " ", A
clipwait 0.1
}
old := ""
tmp := ""
return
#IfWinActive ahk_class AcrobatSDIWindow
^c::
old := ClipboardAll
clipboard := ""
send ^c
clipwait 0.1
if clipboard =
clipboard := old
else {
tmp := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2")
clipboard := tmp
StringReplace clipboard, clipboard, % " ", % " ", A
clipwait 0.1
}
old := ""
tmp := ""
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment