-   Programming (
-   -   bash question: how to make firefox open, but minimize (

chicone 05-03-2011 11:33 AM

bash question: how to make firefox open, but minimize
I am relatively new to scripting, but I was wanting to open a firefox window from a bash script, but have it open, then minimize.

In the script, I have a single instance of:
firefox &

but is there a way to minimize it, versus have it displayed on the screen? I was wanting the command terminal to remain visible and it can't since the firefox window is open in front of it.

I looked all over the place, including the man pages, but to no avail. I can make the height and width changes, but no minimize.

Either that, or to be able to bring the terminal window back to the front automatically.


macemoneta 05-03-2011 12:46 PM

This will work. Install xdotool if you don't already have it from your distribution repositories.


xdotool search --class firefox windowactivate
xdotool key alt+F9

David the H. 05-03-2011 04:04 PM

Other than initial size and position, window control like this is usually handled by the window manager, not the program or the shell that launches it. KDE, for example, has application-specific settings ability, accessible through the window menu or system settings.

There are ways for the shell to talk to the WM, however, such as through dbus.

xdotool is stand-alone program that sends simulated input events from the shell to the X windowing system. Unfortunately, it can't directly handle window raising or lowering, but you can simulate a press of a hotkey combination, which is what macemoneta's example above does.

However, his example may affect all open windows of the program. To be certain you're affecting only the one you're just launching, create a wrapper script like this:


#launch the program in the background, with all command-line options passed to it.
firefox "$@" &

#grab its process id.

#wait for a second so that the window has time to fully register.
sleep 1

#use xdotool to make sure that window is raised to the top.
#this is necessary because it won't directly accept xdotool keypresses otherwise.
#matches both the pid and the class, to ensure we have the right window.
xdotool search --all --pid $pidno --class firefox windowactivate

#use xdotool again to simulate your hotkey combo.  Adjust as necessary.
xdotool key alt+F9

exit 0

chicone 05-03-2011 06:44 PM

Thanks you all. I'll give this a shot when I get home.

smoker 05-04-2011 01:06 AM

Why don't you set the terminal window to be "On top" ?

vdx 05-04-2011 03:01 AM

One more question addition to this....

Can we do this(minimizing firefox) using "gconf-editor" ?
Wt it stands for ?

Is it like windows registry editor ?

[Kindly mark this thread as SOLVED, If you(@chicone) got solution]

All times are GMT -5. The time now is 03:25 AM.