I want to open Chromium browser and then open a couple of web pages, let's say "google.com", and "stackexchange.com". My code for the same is below.

#website 1
xdotool type http://google.com
xdotool key --delay 2000 'Return'
xdotool key 'ctrl+Tab'

#website 2
xdotool type http://stackexchange.com
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 http://google.com http://stackexchange.com &

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
  • Hello, I have tried this approach too. This opens only the first web page and then stops, not proceeding to the second one. This too only works when I have opened another browser window in the background, then and only then this piece of code seems to work. – pi3.14 Feb 23 '18 at 10:16
  • I edited, can you try again ? – Félicien Feb 23 '18 at 10:17
  • your solution did work to open multiple tabs, but yet again when i want to cycle through them I am getting the same issue, i,e, it is not working. I need to have opened another browser in the background to get anything done. Why is this so? thanks – pi3.14 Feb 23 '18 at 10:55
  • What do you mean by 'cycle through them" ? – Félicien Feb 23 '18 at 10:57
  • I want to open a couple of pages and keep moving from one page to another after a span of 5secs (by pressing ctrl+Tab), and keep on doing that. For that, I am using xdotool type option. – pi3.14 Feb 23 '18 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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