Page 1 of 1

Write content of the clipboard to a log file (eg .txt)

Posted: 22 Jun 2018, 19:15
by loek3000
Hope people will understand me.....

I would like to keep a log of all the copying text i collect with ctrl+c..... i've read a ton of examples but didn't find anyone which can do this... so for example:

Some site, some text, i select the text i want to copy, press ctrl+c, from then on i would like the selected copied text to be in a file somewhere on the harddrive AND still must be in the buffer (copied text) so i can use it like i always do...

I've also examed the clipboard scripts but i'm not that good to make an own script

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 22 Jun 2018, 19:33
by gregster
The built-in function OnClipboardChange() seems to be made for this:

Code: Select all

#Persistent
OnClipboardChange("ClipChanged")			; place in script's auto-execute section 
return

ClipChanged(Type) {
    If (type = 1)	; is (new) text in the clipboard?
		FileAppend, % Clipboard "`n", C:\Users\g\Desktop\clip.txt		;then append it to text file 
}
Change the file path of the text file to one that suits you.
Note that if you copy a file in explorer, it's file path will also be saved to the text file, although it will paste the actual file (one of the quirks of the built-in clipboard variable) - if you don't want this, you will have to check the contents of clipboard each time before saving and throw strings out that look like file paths ... ;)

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 04:11
by loek3000
ah great thanx! it works

i would like to have a date in front of the output in the txt file i've tried :


added:

this works:

#Persistent
OnClipboardChange("ClipChanged") ; place in script's auto-execute section
return
FormatTime, TimeString,, MMddyyyy
ClipChanged(Type) {
If (type = 1) ; is (new) text in the clipboard?
FileAppend, % Clipboard "`n ", C:\aa\%A_YYYY%-%A_MM%-%A_DD%clip.txt ;then append it to text file
}

this makes an new file every other day...
i only want to add time in each of the txt files

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 04:16
by MonuKashyap
date=%a_yyyy%-%a_mm%-%a_dd%
Fileappend % clipboard "`n" date "`n", C:\aa\clip.txt

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 04:20
by loek3000
@MonuKashyap thanx but can you review my post above?

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 04:31
by loek3000
Maybe it's not clear, it works for now, but to add: i want to add a timestamp (only hours and minutes) in front of any line in the txt file....

thanx alot for the help so far

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 05:01
by swagfag

Code: Select all

#NoEnv
#Persistent
OnClipboardChange("ClipChanged")
Return

ClipChanged(type) {
	FormatTime, date, A_Now, yyyy'-'MM'-'dd

	if (type == 1)
		FileAppend, % Format("{}: {}`n", date, Clipboard), % Format("C:\aa\{}clip.txt", date)
}

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 05:19
by loek3000
thanx swagfag

but instead of a date can i do a time: hours minutes?

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 06:05
by swagfag
you absolutely can, formattime supports besides date formats, well, time formats, as the name would imply.
for a list of available formats, consult the docs.

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 09:15
by loek3000
yeah but i don't know how to do this....

the file only the date, in the file just the time...

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 10:03
by loek3000
I now have:

#NoEnv
#Persistent
OnClipboardChange("ClipChanged")
Return

ClipChanged(type) {
FormatTime, date, A_Now, yyyy-MM-d (ddd)

if (type == 1)
FileAppend, % Format("{}: {}`n", date, Clipboard), % Format("C:\aa\{} clip.txt", date)
}

which resulted in a file called the date and the first 2 letters of the day (za)

tho i wished IN the text file ONLY the time was visible and NOT the year, month and day...

Re: Write content of the clipboard to a log file (eg .txt)  Topic is solved

Posted: 23 Jun 2018, 10:39
by swagfag
just define another format and youre good to go

Code: Select all

#NoEnv
#Persistent
OnClipboardChange("ClipChanged")
Return

ClipChanged(type) {
	now := A_Now
	FormatTime, date, now, yyyy-MM-dd
	FormatTime, time, now, HH:mm:ss

	if (type == 1)
		FileAppend, % Format("[{}] {}`n", time, Clipboard), % Format("C:\aa\{}clip.txt", date)
}

Re: Write content of the clipboard to a log file (eg .txt)

Posted: 23 Jun 2018, 12:06
by loek3000
yeah i struggled to make this but every time it wasn't exactly what i wanted, this IS, have to make some changes, but i manage

thanx alot!