In my workflow I always have tab 1-3 of chrome as specific pages that never change.

I want to make a keyboard shortcut that will navigate to the second tab with Super+Shift+S.

If I execute the following bash script from a terminal it will proceed to behave as expected but when I tie it to a keybinding from keyboard shortcut settings in the gui it will only achieve focus on Chrome but not proceed to the second command.

wmctrl -a chrome && xdotool key Ctrl+2

Any help will be appreciated.


Try inserting a sleep between wmctrl and xdotool like this:

wmctrl -a " Google Chrome" && sleep 0.5s && xdotool key Ctrl+2

You can play with increasing/decreasing the sleep value if needed.

You could also make your command a little more specific by replacing "chrome" with at least " - Google Chrome". That way, the chances of wmctrl picking the wrong window to raise to focus will be reduced. In other words, the longer the string, the less chance there is that wmctrl may raise and focus a window of some other application that just happens to have "chrome" in the title as seen by wmctrl -l or wmctrl -lx.

A route using only xdotool but still requiring sleep is this:

xdotool search --name " - Google Chrome" windowactivate %1 && sleep 0.5s && xdotool key Ctrl+2


  • Re. the sleep value, I would not reduce it to the minimum that seems to work but keep it as high as convenient for the times when your system maybe using resources for other purposes.
  • if no units are specified for sleep, the default is seconds but I like to include s in any case.
  • the basis for requiring sleep when using a keyboard shortcut to run scripts/commands involving xdotool is explained in this answer.
  • I needed to ctrl+l ctrl+c inside chrome to get the url. It works. Thank you – Hettomei Nov 24 '20 at 13:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.