Today I added that the script warns (TrayTip) when something has been pasted to the clipboard (with the script keyboard shortcut Ctrl+F3, what is copied in the usual way with Ctrl+c, is not saved by this script. This gives you two uses for the copy option), and when the process of converting the clipboard to an HTML file is finished (it takes a while, but you can copy something during the process, but it would overlap messages and would be annoying). It also warns with an exclamation mark when the clipboard is the same as the previous one (a small control of the errors that the user can make).
A message also pops up when you hit paste (Ctrl+F6) on the clipboard. I can't try to control (or limit) at all the programs in which you can paste. It's easier with a warning message.
I have used my own sound files, one is from Windows 10, and in the control panel it has the name "Windows_Startup.wav". The other one, the one that warns, I created it myself —modified only—, I hope it's not too annoying. It is up to each person to change or deactivate them. To control the time of the TrayTip, you have to change it in:
Code: Select all
#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
;#SingleInstance, Force
#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include ViewHtml.ahk
#Include xpath.ahk
#Persistent
;#InstallKeybdHook
;Menu, Tray, Icon,,, 1
global xml
; Check to make sure the XML Document Exists
If (!xpath_load(xml, "Test.xml")) {
; MsgBox, Fail
xpath_save(xml, "Test.xml")
}
; Can only contain one "ROOT" element
MenuName := % "/" . xpath(xml, "/*/@Name/text()") ; Can only have one attribute named Name
MenuType := % xpath(xml, "/*/@Type/text()") ; Can only have one attribute named Type
DynamicMenu(MenuName, MenuType) ; Call DynamicMenu(name, type)
;SetBatchLines, -1
ClipCount := 0
CorpusCount := 0
;FileDelete, Test.xml
if FileExist("HTMLTemp\Text1.html")
MsgBox, 4,, There are clipboards from a previous session `n`n Do you want to delete them?
IfMsgBox Yes
Gosub, Borrado
Else
loop, HTMLTemp\Corpus*.html
CorpusCount := % Floor(A_Index)
ClipCount := CorpusCount
;MsgBox, %CorpusCount% - %ClipCount%
^F3::
;MsgBox, %Clipboard%
ClipTemp := Clipboard
;MsgBox, %ClipTemp%
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
if Not Clipboard=ClipTemp
{
SoundPlay, Clipboard_Sound.mp3
TrayTip, Timed TrayTip, %Clipboard%, 0x1, 0x10, 0x20
SetTimer, HideTrayTip, -1500
}
Else
{
SoundPlay, ambiguity2.mp3
TrayTip, Timed TrayTip, REPEATED CLIPBOARD!, 0x2, 0x10, 0x20
SetTimer, HideTrayTip, -1500
return
}
accData:= GetAccData()
FileAppend,
(
<body lang=ES link=blue vlink="#954F72" style='tab-interval:35.4pt;word-wrap:
break-word'>
<p style='margin:0cm'><b><span style='font-size:16.0pt;font-family:"Calibri",sans-serif;
color:#78230C'>Text extracted from:<o:p></o:p></span></b></p>
), % GetAvailableFileName("HTMLTemp\Text##.html"), CP65001
ClipCount++
FilExists := "HTMLTemp\Text" ClipCount ".html"
XmlTemp := "`t<" ClipCount " Name=""" accData.1 """ Type=""Item""/>`n"
FileAppend, %XmlTemp%, temp.txt
Sleep 300
;MsgBox, %FilExists%
myResult := "<p style='margin:0cm'><span style='font-size:16.0pt;font-family:Calibri,sans-serif;color:#78230C'><a href=" accData.2 ">" accData.1 "</a> <o:p></o:p></span></p>"
FileAppend, %myResult%, %FilExists%, CP65001
ClipboardGet_HTML( Data )
;ReplacedStr := StrReplace(Data, "Â", "")
FileAppend, %Data%, Temp.html
;FileAppend, %ReplacedStr%<br/>, Temp.html
Loop, read, Temp.html
{
If A_Index >6
FileAppend, %A_LoopReadLine%, TempPDF.html
}
Sleep 500
NameCopy := "HTMLTemp\Temp" ClipCount ".html"
FileCopy, TempPDF.html, %NameCopy%
RunWait, conv.exe -b 65001 TempPDF.html temp2.html ,,hide
CorpusCount++
NameCount := "HTMLTemp\Corpus" CorpusCount ".html"
FileMove, Temp2.html, %NameCount%
FileDelete, Temp*.html
SoundPlay, Clipboard_Sound.mp3
TrayTip, Timed TrayTip, Successful Process!, 0x1, 0x10, 0x20
SetTimer, HideTrayTip, -1200
Return
+RButton::
Filedelete, Test.xml
Gosub, CreateXML
Menu, %MenuName%, Show
Return
^F6::
MsgBox, 4,, You have requested to paste all the contents of the clipboard.`nDo you have an open text editor?`n`nMake sure you do not move the mouse, or change the focus on the application.
IfMsgBox No
Return
Else
Sleep, 500
WinClip.Clear()
Loop, %CorpusCount% ;Loop, %Number% ;so many loops are given as clipboard exist
{
if (Errorlevel = 1)
Break
else if (Errorlevel = 0)
{
WinClip.Clear()
html := FileOpen("HTMLTemp\Text" A_Index ".html", "r").read()
WinClip.SetHTML(html)
WinClip.Paste()
WinClip.Clear()
Sleep, 300
html := FileOpen("Line1.html", "r").read()
WinClip.SetHTML(html)
WinClip.Paste()
;WinClip.Paste()
WinClip.Clear()
html := FileOpen("HTMLTemp\Corpus" A_Index ".html", "r").read()
Sleep, 1000
WinClip.SetHTML(html)
WinClip.Paste()
WinClip.Clear()
Sleep, 300
;SendInput {Del}
html := FileOpen("Line2.html", "r").read()
WinClip.SetHTML(html)
WinClip.Paste()
Send, `n
Sleep, 300
}
}
TrayTip, Timed TrayTip, Successful Process!, 0x1, 0x10, 0x20
SetTimer, HideTrayTip, -2000
SoundPlay, Clipboard_Sound.mp3
Return
^F10::
MsgBox, 4,, Do you want to delete all stored clipboards?
IfMsgBox Yes
Gosub, Borrado
Return
^F5::
MsgBox, %CorpusCount% Clipboards will be Converted to a PDF File
Loop, %CorpusCount%
{
if (Errorlevel = 1)
Break
else if (Errorlevel = 0)
{
html1 := "HTMLTemp\Text" A_Index ".html"
FileRead, PDF1, %html1%
FileAppend, %PDF1%<br/>, ToPDF.html
html2 := "HTMLTemp\Temp" A_Index ".html"
FileRead, PDF2, %html2%
FileAppend, %PDF2%<br/>, ToPDF.html
FileRead, html3, CQLine.html
FileAppend, %html3%<br/>, ToPDF.html
}
}
RunWait, conv.exe -b 65001 ToPDF.html TempPDF.html ,,hide
RunWait, wkhtmltopdf.exe TempPDF.html Final_Document.pdf,,hide
FileDelete, ToPDF.html
;FileDelete, TempPDF.html
Run, Final_Document.pdf
Return
/*
^F11::
MsgBox, 4,, Do you want to delete the last entrance of the clipboard?
IfMsgBox Yes
TextDelete := "Text" ClipCount ".html"
CorpusDelete := "Corpus" ClipCount ".html"
;MsgBox, %TextDelete% and %URLDelete%
FileDelete, HTMLTemp\%TextDelete%
FileDelete, HTMLTemp\%CorpusDelete%
ClipCount--
CorpusCount--
Return
*/
^F12::
Pause, Toggle
Return
^Esc:: ExitApp
; Funtion thanks to SoLong&Thx4AllTheFish in https://autohotkey.com/board/topic/5894-function-get-nextfree-available-file-name/
GetAvailableFileName( GivenFileName, GivenPath = "", StartID = 1 )
{
StringSplit, NameArray, GivenFileName, #
Loop
{
Number := A_Index + StartID - 1
Loop, % NameArray0 - 10 - StrLen(Number) ;%
Number = 0%Number%
StringSplit, NumberArray, Number
FileName =
Loop, %NameArray0%
FileName := FileName . NameArray%A_Index% . NumberArray%A_Index%
If not FileExist(GivenPath . FileName)
Return GivenPath . FileName
}
}
Return
ClipboardGet_HTML( byref Data ) ;www.autohotkey.com/forum/viewtopic.php?p=392624#392624
{
If CBID := DllCall( "RegisterClipboardFormat", Str,"HTML Format", UInt )
If DllCall( "IsClipboardFormatAvailable", UInt,CBID ) <> 0
If DllCall( "OpenClipboard", UInt,0 ) <> 0
If hData := DllCall( "GetClipboardData", UInt,CBID, UInt )
DataL := DllCall( "GlobalSize", UInt,hData, UInt )
, pData := DllCall( "GlobalLock", UInt,hData, UInt )
, VarSetCapacity( data, dataL * ( A_IsUnicode ? 2 : 1 ) ), StrGet := "StrGet"
, A_IsUnicode ? Data := %StrGet%( pData, dataL, 0 )
: DllCall( "lstrcpyn", Str,Data, UInt,pData, UInt,DataL )
, DllCall( "GlobalUnlock", UInt,hData )
DllCall( "CloseClipboard" )
Return dataL ? dataL : 0
}
Return
DynamicMenu(name, type) {
Loop, Parse, name, /
If (A_LoopField)
{
MenuPath := MenuPath . "/*[@Name=" . A_LoopField . "]"
ItemName := A_LoopField
}
StringTrimRight, MenuName, name, StrLen(ItemName)+1 ; Make sure the Menu's are named correctly
If (type = "Item") ; type Contained Item
Menu, %MenuName%, Add, %ItemName%, MenuHandler
Else { ; type Contained something other than Item
parseme := xpath(xml, MenuPath . "/*/@Name/text()") ; Grab the next set of names
Loop, Parse, parseme, CSV ; Parse the names
{
i := name . "/" . A_LoopField ; Dynamic Name
j := xpath(xml, MenuPath . "/*[@Name=" . A_LoopField . "]/@Type/text()") ; Dynamic Type
DynamicMenu(i,j) ; Recursive
}
If (type = "Submenu") ; Add all Submenus to the menu
Menu, %MenuName%, Add, %ItemName%, % ":" . name
}
}
Return
HideTrayTip() {
TrayTip
}
Return
MenuHandler:
;MsgBox, You clicked %A_ThisMenuItem% located at %A_ThisMenu%
;MsgBox, You clicked %A_ThisMenuItemPos% located at %A_ThisMenu%
If (A_ThisMenuItem = "Exit this Menu")
{
Gui, Destroy
Return
}
Else
Sleep, 300
WinClip.Clear()
html := FileOpen("HTMLTemp\Text" A_ThisMenuItemPos ".html", "r").read()
WinClip.SetHTML(html)
WinClip.Paste()
WinClip.Clear()
Sleep, 300
html := FileOpen("Line1.html", "r").read()
WinClip.SetHTML(html)
WinClip.Paste()
;WinClip.Paste()
WinClip.Clear()
html := FileOpen("HTMLTemp\Corpus" A_ThisMenuItemPos ".html", "r").read()
Sleep, 1000
WinClip.SetHTML(html)
WinClip.Paste()
WinClip.Clear()
Sleep, 300
SendInput {Del}
html := FileOpen("Line2.html", "r").read()
WinClip.SetHTML(html)
WinClip.Paste()
Send, `n
Sleep, 300
Return
CreateXML:
Filecopy, temp.xml, Test.xml
FileSetAttrib, -R, Test.xml
FileRead, FixString, temp.txt
;MsgBox, %FixString%
vList := "
(
! -
# -
$ -
& -
' -
* -
+ -
, -
; -
: -
@ -
[ -
] -
´ -
% -
\ -
^ -
_ -
` -
{ -
| -
} -
~ -
 -
)"
Loop, Parse, vList, `n
{
oTemp := StrSplit(A_LoopField, "`t")
FixString := StrReplace(FixString, oTemp.1, oTemp.2)
}
oTemp := ""
Sleep, 200
FileAppend, %FixString%, Test.xml
CorpusCount++
TempString := "`t<" CorpusCount " Name=""Exit this Menu"" Type=""Item""/>`n</a>"
FileAppend, %TempString%, Test.xml
CorpusCount--
Return
Borrado:
FileDelete, Test.xml
;Filecopy, temp.xml, temp1.xml
FileDelete, temp.txt
FileDelete, HTMLTemp\Text*.html
FileDelete, HTMLTemp\Corpus*.html
FileDelete, HTMLTemp\Temp*.html
Return