Find window by its name and activate it (bring to foreground)
Problem
From a script, I wanted to bring a specific window to the foreground.
Solution
There is a command-line X11 automation tool called “xdotool”. You will have to install it via apt-get. This command can do a lot, it’s worth checking out its man page.
Find the window ID of a window by its window title (example):
$ xdotool search --name "Rocket Launcher" 37748739
You can also use regular expressions.
Put the focus on this window and bring it in the foreground, i.e. activate it (example):
xdotool windowactivate 37748739
Other goodies
Window ID of the currently active window (example) #1:
$ xdotool getactivewindow 50331675
Window ID of the currently active window (example) #2:
$ xdpyinfo | grep focus focus: window 0x300001b, revert to PointerRoot
(Where 0x300001b == 50331675). “xdpyinfo” can also give you information about the X.Org version, number of screens, screen dimensions, etc.
Get window information (example):
$ xwininfo -id 50331675 xwininfo: Window id: 0x300001b "jabba : bash – Konsole" Absolute upper-left X: 0 Absolute upper-left Y: 24 Relative upper-left X: 0 Relative upper-left Y: 0 Width: 1920 Height: 1032 Depth: 32 Visual: 0x23 Visual Class: TrueColor Border width: 0 Class: InputOutput Colormap: 0x3000001 (not installed) Bit Gravity State: NorthWestGravity Window Gravity State: NorthWestGravity Backing Store State: NotUseful Save Under State: no Map State: IsViewable Override Redirect State: no Corners: +0+24 -0+24 -0-24 +0-24 -geometry 1920x1032+0+24
Categories: bash, ubuntu
Tags: activate window, active window, focus on window, window ID, xdotool, xdpyinfo, xwininfo
Comments (0)
Trackbacks (1)
Leave a comment
Trackback
-
January 10, 2013 at 08:40 | #1Launch just one instance of a Qt application « Python Adventures
Leave a Reply Cancel reply
Blog Stats
- 311,657 hits
Random Post
Recent Posts
Tags
add-on
ajax
api
book
c64
config
convert
css
currency
dropbox
email
flash
generated html source
github
gmail
gnome
hacking
install
mc
mplayer
music
pdf
proxy
random
reddit
retro
scraping
script
security
star wars
summary
tip
tips and tricks
torrent
trick
truecrypt
tutorial
tweak
unity
video
virtualbox
vlc
wallpaper
wget
youtube
Categories
Blogs that I follow
Archives
- May 2013 (4)
- April 2013 (20)
- March 2013 (10)
- February 2013 (7)
- January 2013 (26)
- December 2012 (18)
- November 2012 (13)
- October 2012 (9)
- September 2012 (8)
- August 2012 (7)
- July 2012 (3)
- June 2012 (9)
- May 2012 (16)
- April 2012 (32)
- March 2012 (18)
- February 2012 (17)
- January 2012 (12)
- December 2011 (8)
- November 2011 (18)
- October 2011 (18)
- September 2011 (32)
- August 2011 (13)
- July 2011 (16)
- June 2011 (6)
- May 2011 (14)
- April 2011 (30)
- March 2011 (45)
- February 2011 (42)
- January 2011 (28)
- December 2010 (14)
- November 2010 (29)
- October 2010 (15)
- September 2010 (5)