Home > Mobile >  Trigger Brave "Search Tabs" feature from Autohotkey
Trigger Brave "Search Tabs" feature from Autohotkey

Time:10-09

I would like to be able to trigger "Search Tabs" from Autohotkey, since I have lots of opened tabs this would help me quickly find the tab I am looking for, I know I might be able to loop through all tabs by scripting this, but that's not what I want.

This is what I've done

! a::
  WinActivate, Brave
  Sleep, 100
  Send, {Ctrl}{Shift}a
Return

If I change Send, {Ctrl}{Shift}a with Send, {Ctrl}t is correctly opens a tab, so the problem must be either some error in my {Ctrl}{Shift}a configuration or that Brave is somehow not reacting.

CodePudding user response:

The most appropriate way to activate a specific window and send keystrokes to it is as follows:

! a::
    SetTitleMatchMode, 2 ; if you want to use it only in this hotkey
    IfWinNotExist, Brave
    {
        MsgBox, Cannot find Brave
            Return ; end of the hotkey's code
    }
    ; otherwise:
    WinActivate, Brave
    WinWaitActive, Brave, ,2  ; wait 2 seconds maximally  until the specified window is active
    If (ErrorLevel)  ;  if the command timed out
    {
        MsgBox, Cannot activate Brave
            Return
    }
    ; otherwise:
    ; Sleep 300 ; needed in some programs that may not react immediately after activated
    Send, ^ a
Return

Otherwise the script can send the keystrokes to another window.

For not repeating the whole code in every hotkey you can create a function:

! b::
    SetTitleMatchMode, 2
    Activate("Brave", 2)
    ; Sleep 300
    Send, ^ a
Return

Activate(title, seconds_to_wait){
    IfWinNotExist, % title
    {
        MsgBox % "Cannot find """ . title . """."
            Return
    }
    ; otherwise:
    WinActivate, % title
    WinWaitActive, % title, ,% seconds_to_wait
    If (ErrorLevel) 
    {
        MsgBox % "Cannot activate """ . title . """."
            Return
    }
}
  • Related