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?


6 Answers 6


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.

  1. Find the window ID:

    xdotool search --onlyvisible --name firefox
  2. Set the window size

    xdotool windowsize $WINDOW_ID_GOES_HERE $WIDTH $HEIGHT
  3. 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.

  • 1
    There's a bug with 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
    – ThePhi
    Apr 25, 2018 at 12:33
  • I don't see this bug in Ubuntu 19.10. It's interesting that the other answer, which says that it's impossible, has 20 upvotes.
    – Dominic108
    Jan 1, 2020 at 5:29
  • 3
    xdotool allows you to chain several commands together. so you could do: xdootool search --onlyvisible --name firefox windowmove 100 100
    – Stuart
    Jan 8, 2020 at 15:51
  • This still works well enough, but, if a window has a decoration (like firefox has) it is being treated as part of the window, leaving you with a window slightly smaller than intended. Dec 24, 2021 at 21:57
  • Is there a way to move the window such that the client area of the window starts at the given coordinates, not the window border?
    – Michael
    Jul 30, 2022 at 23:16

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

# 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)
# 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.

  • 1
    Just a little note. The resizing won't work if the window is maximized. So you have to deactivate this property first with: wmctrl -i -r $WID -b remove,maximized_vert; wmctrl -i -r $WID -b remove,maximized_horz; After that I was able to resize the Firefox window.
    – ka3ak
    May 30, 2018 at 7:13
  • Thanks for your answer! On Ubuntu 18.04.3 I had an error with the code; suggest shebang #!/bin/bash at beginning of code for concerned users.
    – Tfb9
    Dec 27, 2019 at 23:48

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.

  • Looks like this doesn't work anymore. Apparently, window.resizeTo only has an effect if the window is a popup created via window.open.
    – hugomg
    Nov 18, 2014 at 18:06

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
   set_window_geometry( 50, 10, 1220, 780 )

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.

  • Doesn't seem to works with LXDE. Absolutely no window event is recognized (nothing is printed when running devilspie2 --debug) Nov 6, 2019 at 15:44

I don't think this is possible by shell commands only, cause it has nothing to do with your windowmanager.
I heard of wmctrl and devilspie which can effect this. But I doubt there is a way to achieve that as simple as you wrote in your example.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .