How to past timecodes from potplayer to the table in script (office word)

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
tuxtulen
Posts: 2
Joined: 22 Mar 2023, 12:41

How to past timecodes from potplayer to the table in script (office word)

Post by tuxtulen » 22 Mar 2023, 12:56

Greetings! I'm translating movies and need the script (which works stable) to automatically add timecodes from video to my file with translation.

Code: Select all

^Enter::
{ if WinExist("ahk_class PotPlayer")
WinActivate
 Send "^c"
    if WinExist("ahk_exe WINWORD.EXE")
        WinActivate   
Send "^v"
Send "{Down down}"  
Send "{Down up}"    
WinActivate("ahk_class PotPlayer")
 }
Sometimes my code just stops working for a while. Do I have any mistakes? Or is it possible to make this code a bit more logical and a bit shorter, so that it works faster, because that's my first try in this area.

Descolada
Posts: 1099
Joined: 23 Dec 2021, 02:30

Re: How to past timecodes from potplayer to the table in script (office word)

Post by Descolada » 22 Mar 2023, 14:38

I would make the following optimizations:

Code: Select all

^Enter::
{
    if WinExist("ahk_class PotPlayer") {
        WinActivate
        WinWaitActive
    } else
        throw TargetError("PotPlayer not found")
    A_Clipboard := ""
    Send "{ctrl down}c{ctrl up}"
    ClipWait(1)
    if WinExist("ahk_exe WINWORD.EXE") {
        WinActivate
        WinWaitActive
    } else
        throw TargetError("Word not found")
    Send "{ctrl down}v{ctrl up}"
    Send "{Down}"
    WinActivate("ahk_class PotPlayer")
}
1) The window may not be active instantaneously after WinActive, so using WinWaitActive afterwards tends to be more reliable.
2) Use ClipWait to verify that Ctrl+C actually copied something to clipboard.

Edit: 3) Using {ctrl down} and {ctrl up} might be more reliable also, but I'm not 100% sure of that.

tuxtulen
Posts: 2
Joined: 22 Mar 2023, 12:41

Re: How to past timecodes from potplayer to the table in script (office word)

Post by tuxtulen » 22 Mar 2023, 14:54

Descolada wrote:
22 Mar 2023, 14:38
I would make the following optimizations:

Code: Select all

^Enter::
{
    if WinExist("ahk_class PotPlayer") {
        WinActivate
        WinWaitActive
    } else
        throw TargetError("PotPlayer not found")
    A_Clipboard := ""
    Send "^c"
    ClipWait(1)
    if WinExist("ahk_exe WINWORD.EXE") {
        WinActivate
        WinWaitActive
    } else
        throw TargetError("Word not found")
    Send "^v"
    Send "{Down}"
    WinActivate("ahk_class PotPlayer")
}
1) The window may not be active instantaneously after WinActive, so using WinWaitActive afterwards tends to be more reliable.
2) Use ClipWait to verify that Ctrl+C actually copied something to clipboard.
Just tried your code. It couldn't repeat copying the timecode on the first attempt. Anyway, thank you for your quick reply.

Post Reply

Return to “Ask for Help (v2)”