Error when automating type option via xdotool

I want to open Chromium browser and then open a couple of web pages, let’s say “”, and “”. My code for the same is below.

#website 1
xdotool type
xdotool key --delay 2000 'Return'
xdotool key 'ctrl+Tab'

#website 2
xdotool type
xdotool key --delay 2000 'Return'

The problem:

1) This piece of code only works when I already have a Chromium browser open. Then only, it opens another Chromium browser (as per the code) and performs everything perfectly.

2) If I don’t have a browser already open, then this script just opens the browser and does nothing.

Where am I going wrong? Why do I need to have another browser open for the code to work?


Chromium open the tabs on its own, without needing xdotool :

chromium-browser &

Will open a new chromium window (if none was opened before) with 2 tabs

then you can switch between the tabs with xdotool with

xdotool search --onlyvisible --class "chromium" windowfocus key 'ctrl+Tab'

if you want to repeat every 5 seconds :

while true ; do sleep 5 ; xdotool key 'ctrl+Tab' ; done

Leave a Reply

Your email address will not be published. Required fields are marked *