Filter on selected text

I use this script all the time, so I thought I'd share it with you. The way it works is this:

1. Select some text that you want to filter on

2. Press F2

The text you selected will be copied to the clipboard and will be pasted in Studio's filter search box and the search will be launched.

 

;Filter on selected text
F2::
Send ^c
Sleep 200
Send ^{F6}
Sleep 200
Send ^v
Sleep 200
Send {Enter}
Sleep 100
Send {Control Down}{Home}{Control Up}{Down}
Return

  • Very handy...

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

  • Hi Nora,

    Thanks for sharing this script. I just tested it. It does not work for me. Previously I used F2 for Quick add term. I changed the shortcut key. F2 is not used. It still does not work. Don't know what's wrong. Please kindly advise if you know the solution. Thanks.

    Regards,
    Ivan
  • Hi Ivan,

    Is the selected text pasted into your Filter search field or does nothing happen at all?
  • You could try increasing the wait times and see what works for your system. For example, increase them to half a second, or even a second, and if the script works, then you can start decreasing them until you find the perfect wait times for you.

    So, for example:

    ;Filter on selected text

    F2::
    Send ^c
    Sleep 500
    Send ^{F6}
    Sleep 500
    Send ^v
    Sleep 500
    Send {Enter}
    Sleep 500
    Send {Control Down}{Home}{Control Up}{Down} 
    Return

    Here's a video showing how the script works, so you can have an idea of what to expect.

  • Thanks Nora. I just find that when I select texts and press F2, it jumps to the first segment. I guess it still has something with the shortcut key. I will try to reset all the settings to see if it works when I have time. Thanks for your video. By the way, does this also apply to target text? Sometimes, I need to filter some target texts too.
  • Hi Ivan,

    You can also try changing the hotkey and use something else instead of F2, but I suspect it's a matter of increasing the wait times, because the behavior you're describing is actually the very last line of the script, Send {Control Down}{Home}{Control Up}{Down}, which means that everything else is probably running too fast.

    The script will work on target text but you would have to change the Search settings of the display filter from In Source to In Target.
  • Hi Nora,

    I checked the script again today. It dawned on me that I changed the shortcut key for Activate Display Filters Search Box to Ctrl+D. It works after I replace F6 with d in the script.

    I tried the script. Filtering source text is perfect. When I switch to In Target, select some target texts, the filter does not work reliably. The selected texts are not copied to the search box. Just wondering if filtering target texts works fine on your side. Thanks.

    Regards,
    Ivan
  • Dear , a routine I always use when depending on text to be copied to the clipboard is the following, it make things smoother and helps troubleshooting:

    CurrentCB = %Clipboard% ;~ back up the current content of the clipboard, in case it is need afterwards
    Clipboard = ;~ empty clipboard to not mistakenly use something already present on the clipboard
    SendInput, ^c ;~ actual copy action
    ClipWait, 5 ;~ wait max. 5 seconds for something to appear on the clipboard
    If ErrorLevel ;~ if after 5 seconds, nothing has appeared on the clipboard, and error is given, a message box informs the user and the script stops its execution; otherwise the code between the parentheses is skipped
    {
        MsgBox, 48, Script title, No text highlighted or problem copying text to clipboard.
        Return
    }
    More code…
    Clipboard = %CurrentCB% ;~ restore the current content of the clipboard

  • I used other shortcut key instead of F2, and increase the sleep time a bit. It works both for source and target texts.

    Acutally, I'm thinking if we can have such a script (or two if one is not possible). Whatever you select, source or target texts, press a key, Studio will filter the strings based on the selected texts. That is to say, we do not have to switch between In Source and In Target manually.