saving multiple clipboard items in text file - alternatives? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dwilbank
Posts: 43
Joined: 15 Mar 2020, 12:59

saving multiple clipboard items in text file - alternatives?

Post by dwilbank » 25 May 2022, 05:51

This is working code that lets me ctrl-shift-c copy up to 9 text items, then paste them back in any order (ctrl-1 through ctrl-9).

Tapping ctrl twice quickly clears the copy queue.
The wav files came from https://evolution.voxeo.com/library/audio/prompts/numbers/index.jsp and I didn't use Windows' internal voice because audio outputs are tricky on my Windows running in OSX BootCamp and it didn't work.

So -- I've heard that if you submit inefficient code, suggestions and fixes will come quickly.
(and there are many inefficiencies)

#1 I want to address is... would writing to an ini file bring any speed or reliability gains?
#2 Could I generate the ctrl-1 through ctrl-9 hotkeys through a single formula (like currying?)

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.

^+c::
Send ^c
sleep 250
clipboard = %clipboard%
FileAppend, %clipboard%###, clipboard_queued.txt
sleep 100
FileRead, text, clipboard_queued.txt
copyArr := StrSplit(text, "###")
SoundPlay, % copyArr.Count() -1 ".wav"
return


~Ctrl::
;double-tap control key to clear your queue
if (A_PriorHotKey = "~Ctrl" AND A_TimeSincePriorHotkey < 200)
{
   	FileDelete clipboard_queued.txt
	SoundPlay, 0.wav
}
Sleep 0
KeyWait Ctrl
return

^Numpad0::
FileDelete clipboard_queued.txt
SoundPlay, 0.wav
return

^Numpad1::
^1::
clipboard := copyArr[1]
sleep 150
Send ^v
if (copyArr[1]) {
	SoundPlay, 1.wav	
} else {
	SoundPlay, 0.wav
}
return

^Numpad2::
^2::
clipboard := copyArr[2]
sleep 150
Send ^v
if (copyArr[2]) {
	SoundPlay, 2.wav	
} else {
	SoundPlay, 0.wav
}
return

^Numpad3::
^3::
clipboard := copyArr[3]
sleep 150
Send ^v
SoundPlay, 3.wav
return

^Numpad4::
clipboard := copyArr[4]
sleep 150
Send ^v
SoundPlay, 4.wav
return

^Numpad5::
clipboard := copyArr[5]
sleep 150
Send ^v
SoundPlay, 5.wav
return

^Numpad6::
clipboard := copyArr[6]
sleep 150
Send ^v
SoundPlay, 6.wav
return

^Numpad7::
clipboard := copyArr[7]
sleep 150
Send ^v
SoundPlay, 7.wav
return

^Numpad8::
clipboard := copyArr[8]
sleep 150
Send ^v
SoundPlay, 8.wav
return

^Numpad9::
clipboard := copyArr[9]
sleep 150
Send ^v
SoundPlay, 9.wav
return

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: saving multiple clipboard items in text file - alternatives?  Topic is solved

Post by mikeyww » 25 May 2022, 06:18

#1: Try it!

#2:

Code: Select all

^Numpad8::
^Numpad9::
SendInput % "{Text}" copyArr[hk := SubStr(A_ThisHotkey, 0)]
SoundPlay, %hk%.wav
Return

RussF
Posts: 1237
Joined: 05 Aug 2021, 06:36

Re: saving multiple clipboard items in text file - alternatives?

Post by RussF » 25 May 2022, 06:25

What is the purpose of this?
dwilbank wrote:

Code: Select all

clipboard = %clipboard%
Russ

dwilbank
Posts: 43
Joined: 15 Mar 2020, 12:59

Re: saving multiple clipboard items in text file - alternatives?

Post by dwilbank » 25 May 2022, 08:55

Thanks Mr mikeyww! - code is nicer now

Mr RussF - not sure - I just had problems when I didn't do it, and I saw it in a similar script...

User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: saving multiple clipboard items in text file - alternatives?

Post by WalkerOfTheDay » 25 May 2022, 09:14

RussF wrote:
25 May 2022, 06:25
What is the purpose of this?
dwilbank wrote:

Code: Select all

clipboard = %clipboard%
Russ
In the docs there is an example like this:

Code: Select all

clipboard := clipboard   ; Convert any copied files, HTML, or other formatted text to plain text.
I guess that's the purpose, converting to plain text.

RussF
Posts: 1237
Joined: 05 Aug 2021, 06:36

Re: saving multiple clipboard items in text file - alternatives?

Post by RussF » 25 May 2022, 09:38

WalkerOfTheDay wrote: I guess that's the purpose, converting to plain text.
Hmm, interesting. I guess I've been missing something all along then (to be fair, I use ClipboardFusion which strips formatting anyway). However, the same page you quoted from, (Clipboard) says at the very top:
Clipboard is a built-in variable that reflects the current contents of the Windows clipboard if those contents can be expressed as text. By contrast, ClipboardAll contains everything on the clipboard, such as pictures and formatting.
(emphasis mine)

So, I guess my puzzlement is this: If ClipboardAll contains the formatting and Clipboard contains only text, why would you need to convert Clipboard? It is already text.

Russ

User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: saving multiple clipboard items in text file - alternatives?

Post by WalkerOfTheDay » 25 May 2022, 09:51

@RussF Couldn't tell you. I just saw that example in the docs, really doesn't make much sense to me either.

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: saving multiple clipboard items in text file - alternatives?

Post by mikeyww » 25 May 2022, 10:20

There are scenarios where the results differ. For example, if you copy formatted text in Microsoft Word, and then paste it, it will remain formatted, unless of course, you remove the formatting first.

Code: Select all

F3::
Send ^c
Sleep, 100
; Clipboard := Clipboard
Send {Down}^v^v
Return
In the scenario that I described, the clipboard initially contains text, but it is formatted text. I admit that the documentation is a bit confusing in this area.

RussF
Posts: 1237
Joined: 05 Aug 2021, 06:36

Re: saving multiple clipboard items in text file - alternatives?

Post by RussF » 25 May 2022, 11:30

@mikeyww, I agree, the docs could be worded a little better here. Thank you for enlightening me.

Russ

Post Reply

Return to “Ask for Help (v1)”