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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

22 Jun 2018, 19:15

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
gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

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

22 Jun 2018, 19:33

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 ... ;)
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

23 Jun 2018, 04:11

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
Last edited by loek3000 on 23 Jun 2018, 04:17, edited 2 times in total.
MonuKashyap
Posts: 112
Joined: 06 Jun 2016, 21:32

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

23 Jun 2018, 04:16

date=%a_yyyy%-%a_mm%-%a_dd%
Fileappend % clipboard "`n" date "`n", C:\aa\clip.txt
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

23 Jun 2018, 04:20

@MonuKashyap thanx but can you review my post above?
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

23 Jun 2018, 04:31

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
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

23 Jun 2018, 05:01

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)
}
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

23 Jun 2018, 05:19

thanx swagfag

but instead of a date can i do a time: hours minutes?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

23 Jun 2018, 06:05

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.
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

23 Jun 2018, 09:15

yeah but i don't know how to do this....

the file only the date, in the file just the time...
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

23 Jun 2018, 10:03

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...
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

23 Jun 2018, 10:39

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)
}
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

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

23 Jun 2018, 12:06

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!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 210 guests