Page 1 of 1

saving multiple clipboard items in text file - alternatives?

Posted: 25 May 2022, 05:51
by dwilbank
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

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

Posted: 25 May 2022, 06:18
by mikeyww
#1: Try it!

#2:

Code: Select all

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

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

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

Code: Select all

clipboard = %clipboard%
Russ

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

Posted: 25 May 2022, 08:55
by dwilbank
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...

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

Posted: 25 May 2022, 09:14
by WalkerOfTheDay
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.

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

Posted: 25 May 2022, 09:38
by RussF
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

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

Posted: 25 May 2022, 09:51
by WalkerOfTheDay
@RussF Couldn't tell you. I just saw that example in the docs, really doesn't make much sense to me either.

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

Posted: 25 May 2022, 10:20
by mikeyww
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.

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

Posted: 25 May 2022, 11:30
by RussF
@mikeyww, I agree, the docs could be worded a little better here. Thank you for enlightening me.

Russ