Jörg Brenninkmeyer
Jörg Brenninkmeyer

Reputation: 3344

How to execute a command in a bash script and then focus the appearing window

I have a bash script like this

#!/bin/sh
firefox &

The Firefox window opens, but it doesn't have focus. What can I do so that it has the focus automatically?

I could use some X window tools / commands, but how do I get the window ID of Firefox? The window name is changing with the URLs displayed and therefore not useful.

EDIT: My window manager is Gnome.

Upvotes: 2

Views: 5059

Answers (1)

horsh
horsh

Reputation: 2779

xdotool is the tool to do so.

The simplest form for your particular task is

xdotool  windowactivate `xdotool search --pid $! `

Upvotes: 5

Related Questions