View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 08-19-2003, 12:54 PM   #1
LQ Newbie
Registered: Aug 2003
Posts: 4

Rep: Reputation: 0
How to bring up application window to front from shell script.

How to bring up application window to front from shell script in X-Windows when you know window id?
I need this because I want to write script which would launch a dictionary only when it is not running and in other case it would bring existing dictionary window to front. When I would assign a shortcut to this script. This script would not let to clutter my window with several dictionary windows when I press couple of times a shortcut, by keeping a single window.

Last edited by aleksas_m; 08-19-2003 at 12:56 PM.
Old 08-19-2003, 01:02 PM   #2
Registered: Aug 2003
Distribution: gentoo
Posts: 62

Rep: Reputation: 15
thats an interesting idea. Id like to know how too.
Old 08-21-2003, 01:22 PM   #3
LQ Newbie
Registered: Aug 2003
Posts: 4

Original Poster
Rep: Reputation: 0
I wrote a little program which takes window id (in hex) as argument and sends that window to top. Here is the source:

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>

int main(int argc, char **argv)
if ( argc != 2 ) {
printf("Usage:\n\ttotop <window id>\n");
return 1;

Display *dsp = XOpenDisplay(NULL);

long id = strtol(argv[1], NULL, 16);
XRaiseWindow ( dsp, id );
XSetInputFocus ( dsp, id, RevertToNone, CurrentTime );

XCloseDisplay ( dsp );

return 0;

You can compile it with:
c++ totop.cpp -L/usr/X11R6/lib -lX11 -o totop
I assumed that you saved it in "totop.cpp".

It has problem I do not know how to fix: if window is in another virtual desktop this program doesn't work. Here another question rises: how to send window to current desktop?

You can get window id using xwininfo. A little script using this program used to call WordNet:

if ps -A | grep wishwn; then # if WordNet already launched
id=$(xwininfo -name "WordNet 1.7.1 Browser" | grep id: | awk "{ print \$4 }")
totop $id
else # launch WordNet


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
new shell window by script or code r2d2 Programming 2 12-14-2005 01:59 PM
Running script in separate shell window louisgag Linux - Newbie 2 06-15-2005 05:11 PM
piping to and 'error' window from termalan (shell script) dna3e8 Linux - Software 2 03-19-2005 11:08 AM
Opening file with default application from shell script? bourbon_beast Programming 4 04-13-2004 01:52 AM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM

All times are GMT -5. The time now is 06:17 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration