[SOLVED] bash question: how to make firefox open, but minimize
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.