LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   bash question: how to make firefox open, but minimize (http://www.linuxquestions.org/questions/programming-9/bash-question-how-to-make-firefox-open-but-minimize-878577/)

chicone 05-03-2011 10: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.

Thanks.

macemoneta 05-03-2011 11:46 AM

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

Code:

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


David the H. 05-03-2011 03: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:
Code:

#!/bin/bash

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

#grab its process id.
pidno=$!

#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 05:44 PM

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

smoker 05-04-2011 12:06 AM

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

vdx 05-04-2011 02: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 02:15 AM.