Multiple clipboard, with title and URL of web page

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Multiple clipboard, with title and URL of web page

Post by wetware05 » 23 Jul 2021, 08:39

Hello

I have created a multiple clipboard for my needs, because those who have found did not do what I wanted or as I loved it.

It consists of copying text from different sources on the Internet, copying the text and adding the title of the page and the URL. It does so every time a text is selected in a browser, and by pressing F8. It is recording the information in a text file. When you want to end, F9 is pressed and copy all the content of the file on the clipboard.

The function of searching the information on the current page (the greatest job of the script), is removed from this page: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702&start=140 RommmCek, thanks!

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.
init:= (5.45+1-5)*100 ; 145

#SingleInstance, Force
SetBatchLines, -1

*F8:: ; using Hotkey with asterisk so Ctrl+Hotkey will reset Obj history
clipboard := ""  ; Start off empty to allow ClipWait to detect when the text has arrived.
Send, ^c
ClipWait  ; Wait for the clipboard to contain text.
    st:= A_TickCount
    accData:= GetAccData() ; parameter: "A" (default), "WinTitle", "ahk_class IEFrame", "ahk_exe chrome.exe", etc.
    Clipboard:= "====================`nTex: " ClipBoard "`n`n Title: " accData.1 "`n`nFrom <" accData.2 ">`n`n"
FileAppend, %ClipBoard%, d:\Test.txt
    ;MsgBox % Clipboard A_TickCount-st "`n`n" accData.1 "`n`n" accData.2
    Return
 
*F9::
FileRead, FullText, d:\Test.txt
Clipboard:= FullText
Return

$Esc:: ExitApp ; 84020 start

;-------Function-------
GetAccData(WinId:="A") { ;by RRR based on atnbueno's https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702
    Static w:= [], n:=0
    Global vtr1, vtr2
    th:= WinExist(WinId), GetKeyState("Ctrl", "P")? (w:= [], n:= 0): ""
    WinGet, bp, ProcessName, ahk_id %th%
    for i, v in w
        if (th=v.1)
            Return [ GetAccObjectFromWindow(v.1).accName(0), ParseAccData(v.4).2 ]
    Return ( [(tr:= ParseAccData(GetAccObjectFromWindow(th))).1, tr.2]
             , tr.2? ( w[++n]:= [], w[n].1:=th, w[n].2:=tr.1, w[n].3:=tr.2, w[n].4:=tr.3): "" ) ; save AccObj history
}

ParseAccData(accObj, accData:="") {
    try   accData? "": accData:= [accObj.accName(0)]
    try   if accObj.accRole(0) = 42 && accObj.accName(0) && accObj.accValue(0)
              accData.2:= SubStr(u:=accObj.accValue(0), 1, 4)="http"? u: "http://" u, accData.3:= accObj
          For nChild, accChild in GetAccChildren(accObj)
              accData.2? "": ParseAccData(accChild, accData)
          Return accData
}

GetAccInit() {
    Static hw:= DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
}

GetAccObjectFromWindow(hWnd, idObject = 0) {
    SendMessage, WM_GETOBJECT := 0x003D, 0, 1, Chrome_RenderWidgetHostHWND1, % "ahk_id " WinExist("A") ; by malcev
	While DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr"
		, -VarSetCapacity(IID, 16)+NumPut(idObject==0xFFFFFFF0? 0x46000000000000C0: 0x719B3800AA000C81
		, NumPut(idObject==0xFFFFFFF0? 0x0000000000020400: 0x11CF3C3D618736E0, IID, "Int64"), "Int64"), "Ptr*", pacc)!=0
        && A_Index < 60
        sleep, 30
    Return ComObjEnwrap(9, pacc, 1)
}

GetAccQuery(objAcc) {
	Try Return ComObj(9, ComObjQuery(objAcc, "{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}

GetAccChildren(objAcc) {
try	If ComObjType(objAcc,"Name") != "IAccessible"
		ErrorLevel := "Invalid IAccessible Object"
	Else {
		cChildren:= objAcc.accChildCount, Children:= []
		If DllCall("oleacc\AccessibleChildren", "Ptr", ComObjValue(objAcc), "Int", 0, "Int", cChildren, "Ptr"
		  , VarSetCapacity(varChildren, cChildren * (8 + 2 * A_PtrSize), 0) * 0 + &varChildren, "Int*", cChildren) = 0 {
			Loop, % cChildren {
				i:= (A_Index - 1) * (A_PtrSize * 2 + 8) + 8, child:= NumGet(varChildren, i)
				Children.Insert(NumGet(varChildren, i - 8) = 9? GetAccQuery(child): child)
                NumGet(varChildren, i - 8) != 9? "": ObjRelease(child)
			}   Return (Children.MaxIndex()? Children: "")
		}	Else ErrorLevel := "AccessibleChildren DllCall Failed"
    }
}
Problems?
1. The text format is lost when paste it into a .txt file. Can the loss be avoided in some way?
2. I put a separation with a line "===================". Can the number of signs "=" be variable.
3. Or failing that ... How to format the clipboard, so that it has a line break every X characters?
4. The function can be in a separate script, to be called from other scripts. How to call a function in a non-open script?

(On the third point, I doubt, then the line breaks in the text editors should be deleted).
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 24 Jul 2021, 12:07

I have been working (and learning) since yesterday in the schedule shared up. With this result:

Code: Select all

#SingleInstance, Force
#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include ViewHtml.ahk

SetBatchLines, -1

*F8::
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
FileAppend, %ClipBoardall%, d:\Test.clip ;Save Clipboard to file
    accData:= GetAccData() ;Get info to URL
myResult := "<a href=""" accData.2 """>""" accData.1 """</a>" ;Create a chain to be converted to HTML
	WinClip.SetHTML(myResult) ;Convert Data to HTML
	;MsgBox % myResult
	FileAppend, %ClipBoardAll%, d:\URL.clip ;Save myResult to file
Return
 
*F9::
;Read Test.clip and test1.clip files and Paste in the current window
FileRead, Clipboard, *c d:\Test.clip
Send, ^v
Sleep 500
FileRead, Clipboard, *c d:\URL.clip
Send, `nFrom: ^v`n
Return
 

$Esc:: ExitApp
Use the WinClip library that is located here: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 and Viewhtml.ahk that contain the following script:

Code: Select all

;-------Function-------
GetAccData(WinId:="A") { ;by RRR based on atnbueno's https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702
    Static w:= [], n:=0
    Global vtr1, vtr2
    th:= WinExist(WinId), GetKeyState("Ctrl", "P")? (w:= [], n:= 0): ""
    WinGet, bp, ProcessName, ahk_id %th%
    for i, v in w
        if (th=v.1)
            Return [ GetAccObjectFromWindow(v.1).accName(0), ParseAccData(v.4).2 ]
    Return ( [(tr:= ParseAccData(GetAccObjectFromWindow(th))).1, tr.2]
             , tr.2? ( w[++n]:= [], w[n].1:=th, w[n].2:=tr.1, w[n].3:=tr.2, w[n].4:=tr.3): "" ) ; save AccObj history
}

ParseAccData(accObj, accData:="") {
    try   accData? "": accData:= [accObj.accName(0)]
    try   if accObj.accRole(0) = 42 && accObj.accName(0) && accObj.accValue(0)
              accData.2:= SubStr(u:=accObj.accValue(0), 1, 4)="http"? u: "http://" u, accData.3:= accObj
          For nChild, accChild in GetAccChildren(accObj)
              accData.2? "": ParseAccData(accChild, accData)
          Return accData
}

GetAccInit() {
    Static hw:= DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
}

GetAccObjectFromWindow(hWnd, idObject = 0) {
    SendMessage, WM_GETOBJECT := 0x003D, 0, 1, Chrome_RenderWidgetHostHWND1, % "ahk_id " WinExist("A") ; by malcev
	While DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr"
		, -VarSetCapacity(IID, 16)+NumPut(idObject==0xFFFFFFF0? 0x46000000000000C0: 0x719B3800AA000C81
		, NumPut(idObject==0xFFFFFFF0? 0x0000000000020400: 0x11CF3C3D618736E0, IID, "Int64"), "Int64"), "Ptr*", pacc)!=0
        && A_Index < 60
        sleep, 30
    Return ComObjEnwrap(9, pacc, 1)
}

GetAccQuery(objAcc) {
	Try Return ComObj(9, ComObjQuery(objAcc, "{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}

GetAccChildren(objAcc) {
try	If ComObjType(objAcc,"Name") != "IAccessible"
		ErrorLevel := "Invalid IAccessible Object"
	Else {
		cChildren:= objAcc.accChildCount, Children:= []
		If DllCall("oleacc\AccessibleChildren", "Ptr", ComObjValue(objAcc), "Int", 0, "Int", cChildren, "Ptr"
		  , VarSetCapacity(varChildren, cChildren * (8 + 2 * A_PtrSize), 0) * 0 + &varChildren, "Int*", cChildren) = 0 {
			Loop, % cChildren {
				i:= (A_Index - 1) * (A_PtrSize * 2 + 8) + 8, child:= NumGet(varChildren, i)
				Children.Insert(NumGet(varChildren, i - 8) = 9? GetAccQuery(child): child)
                NumGet(varChildren, i - 8) != 9? "": ObjRelease(child)
			}   Return (Children.MaxIndex()? Children: "")
		}	Else ErrorLevel := "AccessibleChildren DllCall Failed"
    }
}
I have learned that to keep the intact information of the clipboard, but it has enough limits, because if it records a second string in a file with FileApppend, it deletes the previous file (does not chain the information).

The script makes the following: When you have selected a text in a browser, with the keyboard shortcut Control + F8 copy the text to the clipboard and record it in a file. At the same time, the URL (flat text) and the name of the page in two variables are copied. In a next step converts both variables into an HTML format and records it in a second file.

The Control + F9 keyboard shortcut, paste both files into the current window (in programs not only text, such as Word).

This script loses the ability to be a multiple clipboard. My question is: How to do so that every time you can use the Shortcut + F8 Create a new file, without deleting the previous one? (That increases the file number to Test1, Test2, Test3 ...?

Or do you have to resort to Arrays to keep several clipboard?
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 25 Jul 2021, 06:36

Sunday, bad day to ask for help. :roll:

The following script resolves to save several clipboards from the previous script (it increases the number of the file saved on the hard disk), but now I don't know how to read all the existing ones, (calls a function, which I got from the website, as I say in the script). I imagine you can read multiple files with one loop. If someone knows and I can tell me, if not I'll keep looking for the solution.

Code: Select all

#SingleInstance, Force
#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include VerHtml.ahk

SetBatchLines, -1

*F8::
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
FileAppend, %ClipBoardall%, % GetAvailableFileName("Text##.clip") ;Save Clipboard to incremental file
    accData:= GetAccData() ;Get info to URL
myResult := "<a href=""" accData.2 """>""" accData.1 """</a>" ;Create a chain to be converted to HTML
	WinClip.SetHTML(myResult) ;Convert Data to HTML
	FileAppend, %ClipBoardAll%, % GetAvailableFileName("URL##.clip") ;Save myResult to incremental file
Return
 
*F9:: ;unfinished function, does not work now
;Read Test.clip and test1.clip files and Paste in the current window
FileRead, Clipboard, *c d:\Test.clip
Send, ^v
Sleep 500
FileRead, Clipboard, *c d:\URL.clip
Send, `nFrom: ^v`n
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 - 1 - 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
     }
}
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 25 Jul 2021, 08:39

Final version of this small personal project (always improveable, of course).

(See the second entry to know the necessary libraries).

Small utility of multiple clipboard, which saves the context of the selected on different Internet pages. Useful if you are trying to create a document that contains several text references on the Internet.
  • The control keyboard Control+F8 records temporary files selected in a browser, with the title and URL of the current page.
  • The Keyboard Shortcut Control+F9 sticks all existing clipboard in the window of a program as Word (to maintain the format, or in flat text if it sticks into a text editor as a notepad).
  • When you press the Control+10 keyboard shortcut, a small window comes out to give the option to erase all the temporary files of the clipboard.
(Known problems. Both copying and when pasteing there may be problems if the text is very large or contains many images or many small. Solution: Increase time in the lines with the "Sleep" command.)

Code: Select all

#SingleInstance, Force
#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include VerHtml.ahk

SetBatchLines, -1

*F8::
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
FileAppend, %ClipBoardall%, % GetAvailableFileName("Text##.clip") ;Save Clipboard to incremental file
Sleep 1000
    accData:= GetAccData() ;Get info to URL
	myResult := "<a href=""" accData.2 """>""" accData.1 """</a>" ;Create a chain to be converted to HTML
	WinClip.SetHTML(myResult) ;Convert Data to HTML
	FileAppend, %ClipBoardAll%, % GetAvailableFileName("URL##.clip") ;Save myResult to incremental file
Return
 
*F9::
;Read Test.clip and URL.clip files and Paste in the current window
Loop
   {
   if (Errorlevel = 1)
   break
   else if (Errorlevel = 0)
	{
	clipboard := ""
	TextTemp = Text%A_Index%.clip
	FileRead, Clipboard, *c %TextTemp%
	Send, ^v
	Sleep 1000
	URLTemp = URL%A_Index%.clip
	FileRead, Clipboard, *c %URLTemp%
	Send, `nFrom: ^v`n
	Sleep 500
	}
   }
Return
 
*F10::
MsgBox, 4,, Do you want to delete all stored clipboards?
IfMsgBox Yes
Loop
   {
   if (Errorlevel = 1)
   break
   else if (Errorlevel = 0)
	{
	TextTemp = Text%A_Index%.clip
	FileDelete, %TextTemp%
	URLTemp = URL%A_Index%.clip
	FileDelete, %URLTemp%
	}
   }
else
   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
     }
}
(Entrance and script rewritten on 26-07-21, correcting failures and optimizing waiting times between processes.)
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 26 Jul 2021, 10:33

Hello

I have cleaned unnecessary lines and processes. There was a failure by which when pasteing the content with Control+F9 created an extra line; Resolved (I have created a first loop that finds out the number of clipboard and is the number of times the second loop is executed). The changed the bonding order, and a dividing line is added between each clipboard, which works well if it sticks in an A4 format document, in Word. In the attached .zip package (which also contains the necessary libraries), they are called "linebreak.clip" that is paste as many times as clipboard are believed.

https://mega.nz/file/cMAmDZTC#iVqle6z80lDRmh-bR-k6TsP0VYGEL1Qhn9eyGboaGbM

I do not know much about programming and selfhotkeys, the lack of knowledge the supplose with ingenuity, because I do not want either or I need to know programming. This script use it to copy and paste parts of the Wikipedia in my workflow, which maintains the same format and the final result when paste it is well. It is not well (elegant) if you copy from different sources of the Internet, with different sizes, background colors, etc.

(It is not right that not implement in the script a window control in which you are going to hit, but I do not need it, because I am the "father" of the script and I know when I have to do it. In the Download VA A three small text clipboard. If the script is executed, Word opens and Control+F9 is pressed one example of how the finish is.)

Code: Select all

#SingleInstance, Force
#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include ViewHtml.ahk

SetBatchLines, -1

*F8::
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
FileAppend, %ClipBoardall%, % GetAvailableFileName("Text##.clip") ;Save Clipboard to incremental file
Sleep 1000
    accData:= GetAccData() ;Get info to URL
	myResult := "<a href=""" accData.2 """>""" accData.1 """</a>" ;Create a chain to be converted to HTML
	WinClip.SetHTML(myResult) ;Convert Data to HTML
	FileAppend, %ClipBoardAll%, % GetAvailableFileName("URL##.clip") ;Save myResult to incremental file
Return
 
*F9::
;Read Test.clip and URL.clip files and Paste in the current window
loop, *.clip ;Loop that finds how many clipboard exist in the directory
Number := % Floor(A_Index/2)

Loop, %Number% ;so many loops are given as clipboard exist
   {
   if (Errorlevel = 1)
   Break
   else if (Errorlevel = 0)
	{
	clipboard := ""
	FileRead, Clipboard, *c URL%A_Index%.clip
	Send, From: ^v`n
	Sleep 200	
	FileRead, Clipboard, *c Text%A_Index%.clip
	Send, ^v`n
	Sleep 1000
	FileRead, Clipboard, *c LineBreak.clip
	Send, ^v`n
	Sleep 200
	}
   }
Return
 
*F10::
MsgBox, 4,, Do you want to delete all stored clipboards?
IfMsgBox Yes
Loop
   {
   if (Errorlevel = 1)
   break
   else if (Errorlevel = 0)
	{
	FileDelete, Text%A_Index%.clip
	FileDelete, URL%A_Index%.clip
	}
   }
else
   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
     }
}
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 26 Jul 2021, 14:23

Oh, very well, how beautiful! :o

Apparently the clipboard saved in files with the "clipboardall" option contains all the data while the session has not been restarted or closed, because then it no longer works in the same way. I do not understand anything :eh: , when restarting themselves as flat text and the script does not work the same as during the same session! Is that possible?, Someone can explain it to me. Or is it that it is badly done on my script?

If the script is closed and it is unopened, nothing strange happens. It is assumed that the data (clipboard) is saved in files, which would not have to change. Are data recorded and saved in the memory of the system that I do not know?

Help please, I want to understand it! :wtf:
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 16 Aug 2021, 08:52

Hello.

This post is a monologue :silent: . I'm going to answer myself to the problem of my last entry :lol: . All this information may be worth for other people. At least to understand it. (I also give a solution below all).

This explanation is for Windows 10, I do not know how it will be in other versions of Windows or other operating systems. When something copies to the clipboard, they have a header with a "cryptic" reference numbers. Something like this:

StartHTML: 0000000150.
ENDHTML: 0000011114.
StartFragment: 0000000186.
EndFragment: 0000011078.

It is for use of Windows and refers to a temporarily saved file. Such numbers and references do not serve if the computer is restarted or the section is closed, because the temporary files referred to have deleted Windows. That is why the script of this entry does not work well when restarting and only sticks the flat text, not the original format that could have link or images.

For the script on this page to work, you have to enable the Windows 10 history (it is enabled by default). But not only that, because the record is erased. For Windows, do not erase the clipboard that interest us, you have to anchored them. Which is a long and cumbersome process (with the Windows + V key, the Windows Clipboard Manager is accessed, and you have to anchor the elements of the clipboard you want to maintain and use in this script). It could be resolved existed a keyboard shortcut for this Windows function, but it does not exist.

(Anchored clipboard, Windows saves them in "C:\Users\Name User\Appdata\Local\Microsoft\Windows\Clipboard\", but by security, they are encrypted.)

The point I'm getting at, is why Autohotkey makes use of the Windows Clipboard, instead of having its own system for saving the clipboard. Any other (I use copyq) saves the clipboard information without the bug I'm describing here.

It would be a topic to take into account for future versions of AutohotKey.
Last edited by wetware05 on 17 Aug 2021, 05:47, edited 1 time in total.
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Multiple clipboard, with title and URL of web page

Post by rommmcek » 16 Aug 2021, 14:34

Hi! I was attracted by the topic, then I noticed you are even referring to some of my posts.
I've read this thread very superficially so I don't know exactly what you have already solved and if I can help you at all. but here is my (not finished, but very useful to me) multiple clipboard, which mimics ClipJump's basic functionality w/o most of its issues.
Attachments
Custom Clipboard 3.4.ahk
(12.31 KiB) Downloaded 78 times
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 16 Aug 2021, 15:37

Hello Rommmcek.

I have lowered your clipboard. Call Gdip_All.ahk, which can be downloaded from here https://github.com/Drugoy/Autohotkey-scripts-.ahk/tree/master/Libraries. I see that it has many keyboard shortcuts assigned. Can you tell me the most basic? I have noticed that it does not work as the keyboard shortcuts should be copied and paste.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 17 Aug 2021, 06:51

Hi rommmcek.

ClipJump makes the same mistake described above. When you restart Windows the clipboard has lost the HTML formatting, because it makes use of the Windows clipboard.

I'm trying to incorporate the clipboards from the CopyQ program (https://hluk.github.io/CopyQ/), which are saved in html format (when they originally have this format).

It must be configured as follows:

Image

They can be reused from autohotkey using WinClip Libreries https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/.

Code: Select all

#Include WinClip.ahk
#Include ViewHtml.ahk
F5::
WinClip.Clear()
html := FileOpen("d:\Temp\copyq.html", "r", UTF-16).read()
WinClip.SetHTML(html)
WinClip.Paste()
Return
But there is a problem that the coding is not correct. It is in UTF-8 format and for it to be pasted correctly the format should be UTF-8+BOM (this must be due to Autohotkey). I have not found any script that adds BOM to a UTF-8 format. From here you can download an encoding format converter (https://github.com/JFLarvoire/SysToolsLib/releases) and you can use the following script to do the conversion:

Code: Select all

#NoTrayIcon 
;F6::
;Send, ^c ;Ctrl C
Run, d:\Utilidades\AutoHotkey\Scripts\MultiClipboard Preview\conv.exe -b d:\Temp\copyq_20210817091132793.html d:\Temp\copyq.html ,,hide
I am now working to create a script with a file copy system. Copying and renaming the html files generated by CopyQ, and to be used inside the script I've shared above.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 17 Aug 2021, 14:14

Hi.

I already have the script that makes use of the CopyQ program clipboard, to manage them through AutohotKey. Basically what makes the last .html that has created and processes it to convert it to UTF + BOM, and it changes the name to one more "friendly" and recognizable: the name of the website that the fragment has been extracted of clipboard.

I added the part of the script that would stick the .html file. In the script take on behalf of the clipboard, because it is still in memory.

Code: Select all

#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include ViewHtml.ahk

F4::
Send, ^c ;Copy text select
ClipWait
accData:= GetAccData() ;Get info to URL

;Copy in a variable the name of the last .html file saved in the CopyQ program directory
path := "d:\Temp\*.html"
runwait, %comspec% /c dir %path% /S /B /O-D | clip,, hide
LastFile := StrSplit(clipboard,"`n","`r")[1]
MsgBox, %LastFile%

;Make a copy to have a fixed file name to add to the next statement, which does not allow variables.
FileCopy, %LastFile%, d:\Temp\copyq_temp.html, 1

;Convert file .html UTF-8 to UTF+BOM
Run, d:\Utilidades\AutoHotkey\Scripts\MultiClipboard Preview\conv.exe -b d:\Temp\copyq_temp.html d:\Temp\copyq.html ,,hide

;A name is created for the .html file, from the infomation of the website
Clipboard := "d:\Temp\" accData.1 ".html"
MsgBox, %Clipboard%

;Change Name. html file and delete temporal file
FileMove, d:\Temp\copyq.html, %Clipboard%, 1
FileDelete, d:\Temp\copyq_temp.html
Return

F5::
html := FileOpen(ClipBoard, "r", UTF-16).read()
WinClip.SetHTML(html)
WinClip.Paste()
Return
(The libraries included are in the first post.)

The file can use infinity of times. Now calling it by your file name:

Code: Select all

WinClip.Clear()
html := FileOpen("d:\Temp\Mensaje - Wikipedia - Vivaldi.html", "r", UTF-16).read()
WinClip.SetHTML(html)
WinClip.Paste()
Return
This image is an example by paste it to Word::
Image

The way you get the name of the last file is a bit "bastard" (lines from 11 to 13), it does it from the command line. I have searched for other options with AutohotKey, but I only get the name, not the name and the route. Any most elegant suggestion?
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Multiple clipboard, with title and URL of web page

Post by rommmcek » 17 Aug 2021, 16:09

Again, I took a very short look at your posts. My clipboard script does not save clips to file yet, but I got test lines, which seem to work well (even with your html pic exemple). I didn't restart the PC, but don't see why would behave differently.

Code: Select all

clp:= ClipboardAll
FileAppend, % Clp, test.clip ; The file extension does not matter. /////

Clipboard:= ""

SoundBeep, 4000
sleep, 5000
FileRead, Clip, *c test.clip ; Note the use of *c, which must precede the filename.
Clipboard:= Clip ; \/
SoundBeep, 8000
But then again, maybe I didn't spend enough time reading your posts.

Btw: You got a tiny bug/inconsitancy in one of your lines shold be:

Code: Select all

F4::
Clipboard:= "" ; missing
Send, ^c ;Copy text select
ClipWait
accData:= GetAccData() ;Get info to URL
;...
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 19 Aug 2021, 12:46

Hello Rommmcek.

I do not intend to make a clipboard manager. Nor do I have the level of programming for it. I only made this small utility that can be useful for students or people who want to collect information from the Internet and then paste everything at once, as seen in the video. That possibility (copy from several sources at a time and paste all together) is in programs like ClipBoad Master (https://www.clipboardmaster.de/features/features.html, but I do not like how it does.

On the other hand, the Copyq Clipboard Manager is great, it is open source, and its creators are adding the improvements that their users suggest. Use your own script language, and you can personalize each one.

What my script does can do it copyq if you are told that you get the clipboard 1, then the 2 and so until you finish, but I do not like that method either.

About your corrections. I do not like system beeps, the CopyQ program emits a sound when copying. I do not usually want to keep the pre-clipboard, it is managed by COPYQ, Thank you, of all ways.

As I do not know how much my script has used and about the "defect" of Windows when you lose the HTML formats ("Default" that inherits Autohotkey), I have made the following script to show what I want to say. (The truth is that I got bored, :lol: :lol:).

The last script of this post, seeks a solution to this "problem". I have to incorporate that code to the main script, but it becomes more "useless", because it depends on external programs to AutohotKey.



I'm sorry for my poor English. Use translators.
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: Multiple clipboard, with title and URL of web page

Post by rommmcek » 22 Aug 2021, 18:41

One way would be as you started to convert every new entry to clipboard to common format save/append it to the some storage for later use. Here I can't help much...

Another way would be having a multiple clipboard and then paste last entries to desired target.

There hase been a thread about similar topic here: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=66666&hilit=Mrunal
I do have some code for it, but tested on Word 2003. Let me know if you're interested.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 25 Aug 2021, 19:57

I return to the subject.

Hello, Rommmcek, at the moment I'm going to solve the problems.

I found a function to convert the clipboard to an HTML file (https://autohotkey.com/board/topic/59058-convert-clipboard-data-to-html/#entry373078).

Code: Select all

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
}
But the same problem occurs, which when the country code is pasted, it is erroneous, because the WinClip () function works well with the UTF-8 + BOM files, but not with the UTF-8. I have searched the how to solve it everywhere, and I have given a thousand laps. There does not seem to be a solution by means of autohotkey. Then, the UTF-8 to UTF-8 + BOM converter is still needed.

What said above. This script does not try to be a clipboard manager, but only one utility to copy at the same time from many sources and paste them all at once in Word, or any other text editor that accepts HTML code.

A text of a browser is selected, and by pressing F3 the script makes several processes. Copy the text to the text and collect the information on the page to put it in the header of the text. It sticks with F6 and the head of the place of origin, the text and two separation scripts will be stuck.

(The files of the separation lines are always the same. You do not have to erase them, the attached them in this download with everything you need.)

https://mega.nz/file/1Mg12IBC#TKnKWiinX7FhixHxyaiUmLtofdBd_UfvQ2KMH72GJKg

If you know a little HTML editing, you can change the files of the separation lines, colors or sources or your head sizes in the script.
You can give faults for the times of copying or paste. Change where necessary.

With this method it is resolved not to lose the HTML format, when it is restarted or session is closed.
The files can be kept, but the program will ask at the beginning if you want to delete (with F10 you have the option to delete again). If they are not deleted, they will be chained when paste them with the previous sessions. If you do not want this, you will occur or move them to another folder (\ HTMLTEMP, by default).

Code: Select all

#SingleInstance, Force
#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include ViewHtml.ahk
#InstallKeybdHook

SetBatchLines, -1
ClipCount := 0
CorpusCount := 0


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 

*F3::
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
accData:= GetAccData()
/*
FileAppend,
(
<body lang=es style='font-family:Calibri;font-size:11.0pt'>
<p style='margin:0in;font-family:Calibri;font-size:13.0pt;color:#78230C'>Text extracted from:</p>
), % GetAvailableFileName("Text##.html")
*/
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")
ClipCount++
FilExists := "HTMLTemp\Text" ClipCount ".html"
Sleep 300
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>`n"
FileAppend, %myResult%, %FilExists%

ClipboardGet_HTML( Data )
ReplacedStr := StrReplace(Data, "<html>", "<html><ul>")
ReplacedStr2 := StrReplace(ReplacedStr, "</html>", "</ul></html>")
FileAppend, %ReplacedStr2%, Temp.html
Loop, read, Temp.html
{
   If A_Index >6
   FileAppend, %A_LoopReadLine%, Temp1.html
}
Sleep 500
RunWait, conv.exe -b temp1.html temp2.html ,,hide
CorpusCount++
NameCount := "HTMLTemp\Corpus" CorpusCount ".html"
FileMove, Temp2.html, %NameCount%
FileDelete, Temp*.html
Return

*F6::
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.Clear()
	html := FileOpen("HTMLTemp\Corpus" A_Index ".html", "r").read()
	Sleep, 1000
	WinClip.SetHTML(html)
	WinClip.Paste()
	WinClip.Clear()
	Sleep, 300
	html := FileOpen("Line2.html", "r").read()
	WinClip.SetHTML(html)
	WinClip.Paste()
	Send, `n
	Sleep, 300
	}
}
Return
 
*F10::
MsgBox, 4,, Do you want to delete all stored clipboards?
IfMsgBox Yes 
Gosub, Borrado
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

$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

Borrado:
Loop
      if (Errorlevel = 1)
   break
   else if (Errorlevel = 0)
	{
	FileDelete, HTMLTemp\Text%A_Index%.html
	FileDelete, HTMLTemp\Corpus%A_Index%.html
	}
else
   Return
(Pasting indents the text. If you don't like it, remove line 43 and change in line 44 %ReplacedStr% to %Data%)
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 27 Aug 2021, 14:43

Hello.
I have fixed the above script problems. Problems with counters. The previous script opened an HTML code "<ul>", but did not close it "</ul>", because in the tests I did it did not fail, but it does fail sometimes. Now close the code. but I have two lines of SrtReplace() and I would like to understand how to merge them into one. I have not found any help. I haven't figured out how to do it with regExReplace either..., it's too complicated. :headwall:

Code: Select all

ReplacedStr := StrReplace(Data, "<html>", "<html><ul>")
ReplacedStr2 := StrReplace(ReplacedStr, "</html>", "</ul></html>")
I also wanted to put an error check when pasting. Detect a program. I know how to do it, but what I wanted is that not only detect word, but other programs like OneNote, OpenOffice, libreoffice. Is it possible to make a list, or do you have to create a WinActive line for each of the programs?
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 28 Aug 2021, 06:37

To learn, I wanted to make a menu with the contents of the clipboard, where when selecting a menu component you stick in the current window. It is a new world and it is complicated. When I investigate I found a method by which a menu is created from a .xml file, which needs the XPath.AHK library https://github.com/Paris/AutoHotkey-Scripts/blob/master/xpath.ahk. On the same page someone (at the end) had developed an automation https://autohotkey.com/board/topic/76765-solved-dynamically-creating-a-menu-with-xml/page-2. I have used it for how easy it was. I share it here, in case it is of interest to other people. Although I will surely develop my own menu, because I want it to show a thumbnail of the content of the clipboard and this method does not allow it.

What does the addition new? From each capture of the clipboard, a file called temp.txt that contains the page title is generated from where it has been captured.

Code: Select all

XmlTemp := "`t<" CorpusCount " Name=""" accData.1 """ Type=""Item""/>`n"
FileAppend, %XmlTemp%, temp.txt
There is a new keyboard shortcut (uppercase + right mouse key) to show the contents of the clipboard. When calling this function, a Test.xml file is generated, making call, through Gosub, to a routine that creates it (which has to clean the text of not accepted characters, puts the XML header, adds the text of the file temp.txt and close the file. Fast generated.

Code: Select all

#SingleInstance, Force
#Include WinClipAPI.ahk
#Include WinClip.ahk
#Include ViewHtml.ahk
#InstallKeybdHook
#Include xpath.ahk

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

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::
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
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")
ClipCount++
;FilExists := "HTMLTemp\Text" ClipCount ".html"
XmlTemp := "`t<" CorpusCount " 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>`n"
;myResult := "<p style='margin:0in;font-family:Calibri;font-size:13.0pt;color:#78230C'><a href=" accData.2 ">" accData.1 "</a>`r<p style='margin:0in;font-family:Calibri;font-size:11.0pt'>&nbsp;</p>`r"
FileAppend, %myResult%, %FilExists%

ClipboardGet_HTML( Data )
ReplacedStr := StrReplace(Data, "<html>", "<html><ul>")
;MsgBox, %ReplacedStr%
ReplacedStr2 := StrReplace(ReplacedStr, "</html>", "</ul></html>")
FileAppend, %ReplacedStr2%, Temp.html
Loop, read, Temp.html
{
   If A_Index >6
   FileAppend, %A_LoopReadLine%, Temp1.html
}
Sleep 500
RunWait, conv.exe -b temp1.html temp2.html ,,hide
CorpusCount++
NameCount := "HTMLTemp\Corpus" CorpusCount ".html"
FileMove, Temp2.html, %NameCount%
FileDelete, Temp*.html
Return

+RButton::
Filedelete, Test.xml
Gosub, CreateXML
	Menu, %MenuName%, Show
Return

*F6::
WinClip.Clear()
;loop, HTMLTemp\*.html ;Loop that finds how many clipboard exist in the directory
;Number := % Floor(A_Index/2)

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
	html := FileOpen("Line2.html", "r").read()
	WinClip.SetHTML(html)
	WinClip.Paste()
	Send, `n
	Sleep, 300
	}
}
Return
 
*F10::
MsgBox, 4,, Do you want to delete all stored clipboards?
IfMsgBox Yes 
Gosub, Borrado
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

$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
	}
}

Borrado:
FileDelete, Test.xml
FileDelete, temp.txt
Loop
      if (Errorlevel = 1)
   break
   else if (Errorlevel = 0)
	{
	FileDelete, HTMLTemp\Text%A_Index%.html
	FileDelete, HTMLTemp\Corpus%A_Index%.html
	}
else
   Return

MenuHandler:
;MsgBox, You clicked %A_ThisMenuItem% located at %A_ThisMenu%
;MsgBox, You clicked %A_ThisMenuItemPos% located at %A_ThisMenu%
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
html := FileOpen("Line2.html", "r").read()
WinClip.SetHTML(html)
WinClip.Paste()
Send, `n
Sleep, 300
Return

CreateXML:
Filecopy, temp.xml, 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% `n</a>, Test.xml
Return
You need to have a file from the XML header, with the text below and you have to call it temp.xml, the script always uses this file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<a Name="MyMenu" Type="Menu">
This method has been easy and fast (and has not required learning). I have not written almost code, because I have used processes that I already know well. The merit is from the creator of the library (Aadil) and MrPlow123456 (on the pages referenced above).

(I have not put a control of whether the temp.txt file is previously, or if they have to delete it or not. From one session to another, new text lines are added, which may no longer exist. As I'm not going to continue in this development I haven't thought about how to handle that problem. (the easiest thing to do is to check if the clipboard contents exist, if the script does not exist you have to delete the temp.txt file.(I've already added it to the script))).
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 30 Aug 2021, 09:29

It occurred to me the idea that the session of the current clipboard —the saved by this script— will become directly into a PDF file. I came across several problems, because of the question of the UTF-8 converter to UTF-8 + BOM. I resolved, keeping a copy without converting, which at the end joins in a single HTML file, the result passes through the converter and then becomes PDF (which opens at the end of the process). I have not been able to incorporate the separation lines into the PDF document, which I have "prints" badly. It is awake of being solved. I also have the problem of managing the paragraph jumps to generate the PDF, it is implemented, but it does not always work. I corrected that the conversions do not show strange signs (they come out in the header when creating the PDF file, but not when pasteing in Word :roll: ). Two temporary files are created one erases it and the second keep it, in case you want to give you another use (it is behind a point and coma, on line 156). But you have to erase it if you are going to create another PDF, so that it does not give problems. (I know that you can not overlap several HTML documents, but as it works and does not do it very badly, because it can be accepted).

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
;#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::
clipboard := "" ;Empty clipboard
Send, ^c ;Copy text select
ClipWait
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
Return

+RButton::
Filedelete, Test.xml
Gosub, CreateXML
	Menu, %MenuName%, Show
Return

^F6::
WinClip.Clear()
;loop, HTMLTemp\*.html ;Loop that finds how many clipboard exist in the directory
;Number := % Floor(A_Index/2)

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
	}
}
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

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
The HTML to PDF converter works on the command line (cmd), download from here: https://wkhtmltopdf.org/

I added the option to exit the menu, which is activated with Mays+Right mouse button.

I added that the script was paused (with Ctrl+F12), but ignores it (Line 174). Can someone help me with this problem? :headwall:

Keyboard shortcuts that are used:
  • Copy Ctrl+F3
    Generate PDF file Ctrl+F5
    Paste Ctrl+F6
    Delete all Ctrl+F10 portaples
    Delete the latest CTRL+F11 clipboard (now it is deactivated, because I have to solve problems)
    Pause the Ctrl+F12 script
    Show Menu from MAYS+Right Mouse Button
In this download everything is necessary. In the previous one was the converter (CONV.EXE) for x64, but in this download I have put version x32, so that it is more compatible. https://mega.nz/file/sdR2TDLA#q4xH-gS5cjBzxNesJmWhbxapLvGqB5x4o8jqKDXm-3U (In the download there is a clipboard session and a PDF document generated by the script). In this direction you can download the converter (it will always be safer to use): https://github.com/JFLarvoire/SysToolsLib/releases

I have added the encoding for the headers in the script. Let's see if now it works less erratically. The line separator issue in the PDF file is now resolved. Now everything works pretty well... for an automated process! Whoever wants something better, should do the whole process by hand. :lol: (I have uploaded a new download, because the line files were missing.)
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Multiple clipboard, with title and URL of web page

Post by wetware05 » 31 Aug 2021, 13:34

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.

(Without sounds and warnings you go blind. Too many failed clipboard use cases in Windows.)

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

SetTimer, HideTrayTip, -1500

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
Archive with everything you need: https://mega.nz/file/kUonACaL#6rBr_1u3WMYo1TeqcV_49UFF6elshxam4Zef7q4VaL8
Post Reply

Return to “Ask for Help (v1)”