How to execute a command in a bash script and then

2019-04-14 12:28发布

问题:

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.

回答1:

xdotool is the tool to do so.

The simplest form for your particular task is

xdotool  windowactivate `xdotool search --pid $! `