Please note: On Sunday 16th May 00AM – 04AM CEST we will be performing planned maintenance on the RWS Community website. During this time you will not be able to access the website and post/reply. Apologies for the inconvenience.

Paste text from another program into Studio, one sentence per segment

For this script to work, the block of text needs to be pasted into the first segment before activating the script. Furthermore, the "Use Regular Expressions" checkbox in the Find dialog in Studio must be unchecked before running the script, as the script checks and then unchecks the box each time the sequence is run. The script assumes that there's a hard return between each new sentence/segment. See a short demo video of the script in action here: 

 

 

#IfWinActive ahk_exe SDLTradosStudio.exe
;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-
; Cuts text AFTER the Regex pattern, then pastes it into the next segment. The regex pattern is new line \n.
; After pasting the text into the first segment, press Windows+V to activate
;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-

#v::
InputBox,Var,Paste one sentence per segment (by Nora Díaz), How many times do you want to run the sequence?
loop, % Var
{
Send ^{PgUp}
Sleep 100
Send, ^f
Sleep 200
Send, \n
Sleep 200
Send !t
Sleep 200
Send !u
Sleep 200
Send !n
Sleep 200
Send !u
Sleep 200
Send {Esc}{Right}
Sleep 100
Send ^+{PgDn}
Sleep 100
Send ^x{Delete}{Backspace}
Sleep 100
Send {Down}^v
Sleep 200
}
Return

  • Good Nora,
    I wished I had this script before!
    I'd modify it in order:
    - to count automatically the lines to be pasted
    - to avoid pasting the text in the first segment in Studio (just the clipboard should be fine).
    Any volunteers?
    (I'm busy with GDPR sutff)
  • Hi Jesús,

    How about something like this as a starting point?

    #v::
    Loop, parse, clipboard, `n, `r
    {
    SendRaw, %A_LoopField%
    Send {Down}
    }
    return

    I found this here and only adapted it slightly by changing an {Enter} to a {Down} to move to the next segment. However, I can't get it to work reliably and text sometimes is parsed in the wrong place.

  • Maybe some Sleep after the SendRaw / Send commands?
  • No, I'd tried that and it doesn't help. The issue is that sometimes two strings are pasted into the same segment, so I also thought a little wait time would help, but apparently it's something else.
  • Yes, I could repo it.

    The reason is that SendRaw command is really reall slow and I think the script was “fighting” with Studio whith the 100% matches.

    Anyway, I created the following script which works fine for me:

    #v::
        target := Object()
        Loop, parse, clipboard, `n, `r
            target[A_Index] := A_LoopField


        nmax := target.MaxIndex()
        Loop %nmax%    
        {
            clipboard := target[A_Index]
            SendInput {control down}v{control up} ; paste from clipboard
            SendInput {Down}
        }
    return

    In case you want to edit the script:

    • The 1st loop populates the array target with each line of the Clipboard.
    • The 2nd loop copies each element of the array in the Clipboard, pastes it (much faster than Send comands) and goes down 1 line in Studio.
    • I’ve tested it with a 100-line Clipboard and no problem (as long as Trados Studio keeps the focus).
    • I’ve tested with just plain text. To get also the tags, we'd need a different script. I didn’t try…

    Does it work for you?

  • Hi Jesus,

    I've just tried it and it doesn't work for me. The script will sometimes paste the second or third segment into the first one, and then will only go down without pasting anything else.

  • Great idea, Nora! Your script works for me.
    Jesús: in your script, I get the same glitch with empty segments that Nora mentions.

    I often copy text from a paragraph (without hard returns between sentences). So to use your scripts, I'd first have to add the hard returns.
    Am I right in thinking that Studio F&R doesn't allow regex in the "replace with" box? I'm trying to replace periods followed by a space
    \.\s
    with a period and hard return:
    \.\r
  • Hi Emma,

    I think it would be easier to modify the script, using \.\s instead of \n and getting rid of the part that deletes the hard return. Would that work? That way you don't have to do an extra replace operation. And, by the way, you are correct, the replace box only accepts a combination of regular text and backreferences (I'm not sure what the right way of explaining that is), so doing what you're trying to do would result in literal insertion of \.\r into your text.
  • Hi Emma,

    I tried this and it works when the text is separated by periods. Great addition! 

    #v::

    InputBox,Var,Paste one sentence per segment (by Nora Díaz), How many times do you want to run the sequence?

    loop, % Var

    {

    Send ^{PgUp}

    Sleep 100

    Send, ^f

    Sleep 200

    Send, \.

    Sleep 200

    Send !t

    Sleep 200

    Send !u

    Sleep 200

    Send !n

    Sleep 200

    Send !u

    Sleep 200

    Send {Esc}{Right}{Del}

    Sleep 100

    Send ^+{PgDn}

    Sleep 100

    Send ^x

    Sleep 100

    Send {Down}^v

    Sleep 200

    }

    Return

  • That's fab, Nora!
    I've even removed the sleep lines and it still works for me!
  • Amazing! Your new computer is faster than mine, for sure. : )
  • Working with Nora, we think that adding some Sleep commands make the script work (although the exact delay dependes on the PC):
    #v::
    target := Object()
    Loop, parse, clipboard, `n, `r
    target[A_Index] := A_LoopField

    nmax := target.MaxIndex()
    Loop %nmax%
    {
    clipboard := target[A_Index]
    Sleep 200 ; maybe Sleep 500
    SendInput {control down}v{control up} ; paste from clipboard
    Sleep 200
    SendInput {Down}
    }
    return
  • These scripts are making me think I need a new computer! : ) Jesus's awesome script is finally working for me after adding a 500 ms sleep instead of 200.