Copying and pasting line-by-line from a .txt file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
reetis
Posts: 8
Joined: 03 Dec 2022, 11:54

Copying and pasting line-by-line from a .txt file

Post by reetis » 03 Dec 2022, 12:14

Hello,

I am in need of a script that takes a line from a .txt file, pastes the line into a text field in a website AND presses CTRL+ENTER, and then does the same thing with the next line within the .txt file (the script can take the subsequent line in the .txt file or delete the line that was copied previously, the .txt file does not matter). It would be nice to have a 2s sleep between the CTRL+ENTER'ing and also if the script would ignore the lines starting with "[" or "♪".

Code: Select all

$^c::
Clip := []
clipboard =
sleep 200
SendInput, {ctrl down}c{ctrl up}
clipwait, 1
Text := Clipboard
loop, parse, text, `n, `r
{
    if (A_LoopField = "") or RegExMatch(A_LoopField, "^@")
        continue
    thisline++
    Clip[thisline] := A_LoopField
}
thisline := ""
return

^s::
line++
if !Clip[line]
    line := 1

clipboard := Clip[line]
send ^v
sleep 200
return
Above is the script that I found via google, however as you can probably see I have no experience with AHK scripts and would really appreciate if you could tweak the script above to my needs or if you could write a new script yourself, for which I would be really grateful. Thank you!

reetis
Posts: 8
Joined: 03 Dec 2022, 11:54

Re: Copying and pasting line-by-line from a .txt file

Post by reetis » 04 Dec 2022, 03:57

Hello everybody again,

I have tested the procedure and found out that ALT+TAB after every copy and every paste would work well for my task.

So basically the script would be a for loop that copies a line from a .txt file, ALT+TAB's once, pastes the line, presses CTRL+ENTER and ALT+TAB's again, and the first iteration of the for loop is done. And that process is repeated until the end of the .txt file is reached.

Was the above explanation better than my original one? Looking at it now it seems kind of jammed up.

Thanks

reetis
Posts: 8
Joined: 03 Dec 2022, 11:54

Re: Copying and pasting line-by-line from a .txt file  Topic is solved

Post by reetis » 04 Dec 2022, 04:27

Hello,

Update: it seems that I don't even need to alt+tab. AHK is smart and can use the file in the directory without it needing to have the actual file open.

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.

Sleep, 2000
Loop
{
	FileReadLine, line, C:\Users\Paul\Desktop\sas.txt, %A_Index%
	{
		SendRaw %line%
		Send ^c
		Send ^{enter}
		Sleep, 1000
	}
}
return
!Escape:: exitapp
Above is the code that I wrote and it actually works ok. All I need is your help on making the script ignore the lines starting with "[" or "♪".. Also, how would I make the script stop once the end of the .txt file is reached, because now it pastes the last line until I stop the script with alt+escape?

Thank you.

Post Reply

Return to “Ask for Help (v1)”