Copy source text segment with AutoHotkey

The following AutoHotkey script copies the source text segment into the Clipboard.

Requirement: segment must be unlocked.

 

; ------------------------
; Copy source text segment
; CTRL + SHIFT + C
; ------------------------
^+c::
    CheckKey_CONTROL_Up()
    CheckKey_SHIFT_Up()
    
    ; Select all in TARGET
    SelectAll()
    ; Copy all (text + tags) from TARGET
    Copy()
    Target := ClipboardAll    
    
    ; Copy from SOURCE to TARGET
    SendInput !{Insert}
    ; Select all + Copy text
    SelectAll()
    Copy()
    Source := Clipboard
    
    ; Restore TARGET
    length := StrLen(Target)
    if (length)
    {
        Undo()
        SendInput {Right}
    }
    ; Delete the following 2 lines (else + SendInput)
    ; if you want to insert SOURCE > TARGET
    ; whenever TARGET is empty
    else
        SendInput !{Delete}  
    
    ; Copy SOURCE text to Clipboard
    Clipboard := Source
return


Copy()
{
    clipboard = ; Empty Clipboard
    SendInput {control down}c{control up}
    ClipWait, 0
}

Paste()
{
    SendInput {control down}v{control up}
    Sleep, 200
}

SelectAll()
{
    SendInput {ctrl down}a{ctrl up}
}

Undo()
{
    SendInput {ctrl down}z{ctrl up}
}

; Check if CONTROL key is UP
CheckKey_CONTROL_Up()
{
    while GetKeyState("Control", P)
        Sleep, 20
}

; Check if SHIFT key is UP
CheckKey_SHIFT_Up()
{
    while GetKeyState("Shift", P)
        Sleep, 20
}

Parents Reply
  • I think that something like this will work:

    ExportedFile := "Exported file.txt"

    SourceAndTarget  := Source .  "`t" . Target  . "`r`n"

    FileAppend, %SourceAndTarget  %, %ExportedFile%

    It'll export Source and Target to a tab separated TXT file in the same folder as the AHK script.

    If you can loop all the segments, you've got it!

    Notes:

    • Not compulsory, but you might want to use the function FileDelete to initialize the exported file.
    • I've had issues with carriage returns in the Target (they go to another line in Excel). I didn't find out a solution, sorry… Be careful with them.
    • Anyway, are you sure that the SDLXLIFF converter for Microsoft Office plugin is not enough? Just some column and tag cleaning in Word or Excel might be faster & easier.

    Please let me know how it goes

    … Jesús Prieto …

Children