Multiple clipboard, with title and URL of web page
Posted: 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!
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).
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"
}
}
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).