How to set window size and location of an application on screen via command line?
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
I managed to do this (with the help of this forum), although if you find any other solution, please tell me as it will probably be more robust: unix.stackexchange.com/questions/40209/…
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.
xdotool search --onlyvisible --name firefox
xdotool windowsize $WINDOW_ID_GOES_HERE $WIDTH $HEIGHT
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.
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
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.
xdotool allows you to chain several commands together. so you could do: xdootool search —onlyvisible —name firefox windowmove 100 100
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.
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?
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.
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.
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.
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.
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.
Resizing a window to a set size in Linux
Anyone knows a good way to resize any window to for example 640×480? Reason is, of course, screencasting. Under windows I’ve used ZoneSize from donationcoder. (Btw: For Firefox it’s easy, just use the web developer toolbar.)
4 Answers 4
$ wmctrl -l 0x00c00003 -1 rgamble-desktop Bottom Expanded Edge Panel 0x00c00031 -1 rgamble-desktop Top Expanded Edge Panel 0x00e00022 -1 rgamble-desktop Desktop 0x0260007c 0 rgamble-desktop Google - Mozilla Firefox
To resize a window based on its title:
wmctrl -r Firefox -e 0,0,0,640,480
The arguments to the resize option are gravity,X,Y,width,height so this will place the window at the top-left corner of the screen and resize it to 640X480.
you can also specify the window with -r ‘:SELECT:’ . That way, you can point and click the window that you want to resize.
Using wmctrl, there is also some pre defined states:
If a window is currently in the state maximized , it won’t respond to a resizing in pixels using the -e parameter^. This is where the -b param is useful.
The -b option expects a list of comma separated parameters: «(remove|add|toggle),PROP1,PROP2]»
wmctrl -r Firefox -b toggle,maximized_horz
wmctrl -r Firefox -b toggle,maximized_vert ----- --------------- remove modal add sticky toggle maximized_vert maximized_horz shaded skip_taskbar skip_pager hidden fullscreen above below
About the precise question, the -e param allow resizing by values as follow:
Gravity, position X, position Y, window width, window height
// gravity,x,y,w,h wmctrl -r "Resizing" -e 0,0,0,640,480
How do I change the dynamically change the window size with Ubuntu on VirtualBox [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Ive installed Ubuntu inside of a Sun VirtualBox. When I maximise the VirtualBox window the Ubuntu window stays the same size and does not dynamically grow with the size of the VirtualBox window. Ive seen this done before. How do I set it up? (And no Im not just looking for how to increase the screen resolution) Thanks
This does not belong here, it belongs to superuser.com..however try installing the guest addin that come along with the virtual box, I was having the same problem, and it worked for me.
4 Answers 4
You need to install the VirtualBox Guest Additions.
Go to Synaptics an mark the packages:
virtualbox-ose-guest-utils virtualbox-ose-guest-x11
or go to the console and type:
sudo apt-get install virtualbox-ose-guest-utils virtualbox-ose-guest-x11
This will enable most of the VirtualBox drivers in your system.
If you need USB support, you need to install the binary guest additions from the devices menu of your VirtualBox window instead. They have more functions than the OSE ones, but you need to install them manually. This is described at ubuntu-tutorials
Edit: updated Link to a newer article
Installed the above packages, then went ‘Devices’ >’Install Guest Additions’, after which it mapped a CDROM onto the desktop. Inside the files did not match the tutorial, instead it had a readme file..
README: Sun VirtualBox Guest Additions Where have the Windows drivers gone? — The Windows Guest Additions drivers were removed from this directory to save space on your hard drive. To get the files you have to extract them from the Windows Guest Additions installers: To extract the 32-bit drivers to «C:\Drivers», do the following: VBoxWindowsAdditions-x86 /extract /D=C:\Drivers I ran the above command ‘VBoxWindowsAdditions-x86 /extract /D=C:\Drivers’ and got the error ‘VBoxWindowsAdditions-x86: command not found’.. what next?
You need just one of them, either the packages mentioned above, or the guest additions from the devices menu. You have to make sure your OS-settings are correct for your virtual machine (They have Ubuntu as an option). Then call «install guest additions» and run «./VBoxLinuxAdditions-x86.run» at the mounted CD.