I want Firefox window to be opened in a specific size, and location on screen using a shell command, for example:
firefox myfile.html size 800x600 location bottom-left
Is there such a command?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI want Firefox window to be opened in a specific size, and location on screen using a shell command, for example:
firefox myfile.html size 800x600 location bottom-left
Is there such a command?
Here is a community version of the answer by Yokai that incorporates examples offered by Rudolf Olah.
You can use the tool called xdotool
to control window size and location. Not only that, any script you write in bash
, using xdotool
, can be setup to work with a fully maximized window and it can be scripted to set the window size and x:y coordinates by manipulating the mousemove
and click
commands.
Find the window ID:
xdotool search --onlyvisible --name firefox
Set the window size
xdotool windowsize $WINDOW_ID_GOES_HERE $WIDTH $HEIGHT
Move the window
xdotool windowmove $WINDOW_ID_GOES_HERE $X $Y
For example, if the window id for firefox is 123 you would do this:
xdotool windowsize 123 800 600
xdotool windowmove 123 0 1080
The bottom-left positioning will have to be figured out based on your screen resolution.
xdotool
, wmctrl
etc.. and Ubuntu, XFCE (that I have): if the window has already launched in full screen mode, you can't move it anymore: bugs.launchpad.net/ubuntu/+source/unity/+bug/971147
xdootool search --onlyvisible --name firefox windowmove 100 100
As far as I know, this is not possible as Firefox does not accept commands to control the window. That's also (mostly) the responsibility of the window manager, so I doubt that there ever will be parameters to do that. However, you can control the window with wmctrl, but that's going to be a little bit difficult:
#!/usr/bin/env bash
firefox -new-instance -new-window "http://www.reddit.org" &
# Process ID of the process we just launched
PID=$!
# Window ID of the process...pray that there's
# only one window! Otherwise this might break.
# We also need to wait for the process to spawn
# a window.
while [ "$WID" == "" ]; do
WID=$(wmctrl -lp | grep $PID | cut "-d " -f1)
done
# Set the size and location of the window
# See man wmctrl for more info
wmctrl -i -r $WID -e 0,50,50,250,250
There might be more clever ways to do it, and there are some interoperability issues with Firefox (e.g. that no other instance is running) but it should get you going.
#!/bin/bash
at beginning of code for concerned users.
This doesn't solve the problem of the position, but at least you can set dimensions :
firefox -width 200 -height 500
In the past I have created an HTML document that would set the window size with Javascript then redirect to the page I wanted. It's a stupid hack but, hey, it works.
I do this all the time. I use DevilsPie2, however, because it's more robust. It uses the LUA scripting language, which isn't very difficult.
Here's my lua script for Thunderbird, which I want to open on the far left monitor (laptop screen) when it opens:
if (get_window_name()=="Mozilla Thunderbird") then
pin_window()
set_window_geometry( 50, 10, 1220, 780 )
end
where 50 = X coordinate (for upper-left corner of the window)
10 = Y coordinate ( " " )
1220 = window width
780 = window height
To set this up, you create a directory in your home configuration (on Ubuntu-like distributions) named devilspie2, eg /home/$USERNAME/.config/devilspie2
For Thunderbird, I created thunderbird.lua, though the filename doesn't matter. I have a different filename for each application though you can put everything into one script file if you wish. Set devilspie2 to start automatically when you login, eg /home/$USERNAME/.config/autostart/devilspie2.desktop
Here's a link to a good page about various options available to your lua script: https://github.com/gusnan/devilspie2/blob/master/README
One note: The scripts don't have to be executable. Mine are 664 and work fine. A few of the other programs I control are openconnect, pidgin, RecordMyDesktop, timeshift, xeyes, xload, & yad. I use pin_window on them so they appear on all desktops, plus other commands depending on the application.
devilspie2 --debug
)
Nov 6, 2019 at 15:44