30

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?

18

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:

#!/bin/sh

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.

  • 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 '18 at 7:13
18

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.

3

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 '14 at 18:06
2

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.

1

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.

0

This doesn't solve the problem of the position, but at least you can set dimensions :

firefox -width 200 -height 500

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.