Open a text file and go to the end

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tcebob
Posts: 21
Joined: 23 Jan 2017, 21:40

Open a text file and go to the end

26 May 2018, 17:11

Code: Select all

^F12::Run "C:\Program Files\TextPad 8\TextPad.exe" "c:\ProgramData\AVAST Software\Avast\report\Quick.txt"
	 Send ^{end}
This opens the log file but does not move to the end. What's wrong?
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Open a text file and go to the end

26 May 2018, 17:28

it might be sending the ^{end} before the file loads

try creating a script

Code: Select all

q::
Send ^{end}
ExitApp
open your file manually then hit q

see if it goes to the bottom
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Open a text file and go to the end

26 May 2018, 17:35

As said, the key is likely sent too early. Maybe WinWait would be in help.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
AHKd00b
Posts: 10
Joined: 16 May 2018, 16:12

Re: Open a text file and go to the end

26 May 2018, 19:09

This should do the trick:

Code: Select all

^F12::
RunWait "C:\Program Files\TextPad 8\TextPad.exe" "c:\ProgramData\AVAST Software\Avast\report\Quick.txt
Send ^{end}
return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Open a text file and go to the end

26 May 2018, 20:13

I looked at your code as well and I see a hotkey definition on the same line as a command. Consequently ...
The following line of code does not get executed. That's your problem right there. So use correct syntax for multiple commands to solve.

Next will be a problem already identified above. You should wait for the target window to show before sending keystrokes off into the void.
Use WinWaitActive is my suggestion for the extra line of code.

Code: Select all

^F12::
    Run "C:\Program Files\TextPad 8\TextPad.exe" "c:\ProgramData\AVAST Software\Avast\report\Quick.txt"
    WinWaitActive, ahk_exe TextPad.exe Quick.txt ; <<<<< adjust here
    Send ^{end}
Return
Last edited by wolf_II on 26 May 2018, 22:37, edited 2 times in total.
tcebob
Posts: 21
Joined: 23 Jan 2017, 21:40

Re: Open a text file and go to the end

26 May 2018, 21:26

Thanks, AHKd00b. According to one resource "RunWait will wait until the program finishes before continuing." That would mean the Send ^{end} would never happen because it applies to the open program. Actually, I tried all variants and there doesn't seem to be a difference between "Run" and "RunWait" in this case. (Somehow, I lost the closing " and got error comments until I fixed it.)

So I'm still not able to run the editor and go to the bottom of the file.

Hold on . . . WinWait? Um, I'll try that.

Might work but now the system can't find the Editor (Textpad). It's there and my usual shortcut finds it but something is amiss. I will reboot.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: SmithyZoomZoom and 160 guests