How to specify geometry (e.g. 1280x720) for a new browser window?
Solution 1
I don't know if you can start a web browser with a specified size but you can resize it after with wmctrl but i guess it is similar to xdotool
method (without click) so it's maybe not what your are looking for.
E.g
#!/bin/sh
wid=`wmctrl -l | grep Firefox | grep "Stack Overflow" | cut -d " " -f 1`
wmctrl -i -r $wid -e 0,0,0,800,600 -b remove,maximized_vert,maximized_horz
If you've got only one window :
wmctrl -r mozilla -e 0,0,0,800,600 -b remove,maximized_vert,maximized_horz
-e -> gravity,left,up,width,height
-r -> Id with -i
or window name
-b -> unmaximize the window, otherwise resize will not works
EDIT
I think you can't use PID because for example with firefox you will have only one PID even if you've got more than one window, but if your are sure that is not the case you can do something like this (i think it will works):
PID=....
wid=`wmctrl -lp | grep " $PID " | cut -d " " -f 1`
wmctrl -i -r $wid -e 0,0,0,800,600 -b remove,maximized_vert,maximized_horz
wmctrl -lp
seems to list windows in opened order (really not sure about that), so you can use tail -n 1
to get only the last window with the PID you are looking for.
wid=`wmctrl -lp | grep " $PID " | tail -n 1 | cut -d " " -f 1`
Solution 2
As listed here => https://peter.sh/experiments/chromium-command-line-switches/
Sets the initial window size. Provided as string in the format "800,600". ↪
Paul
PhD Social Science (Economics), Caltech and Interested in design of smart marketplaces and auctions, economic and financial decision support, related prototypes and simulation software. Available for short term projects. Contact me at [email protected] Blog: http://www.sunshineonacloudy.net Big Data, Economics & Finance, Apache Spark, Google BigQuery, Other stuff... Open Source Projects: armdisarm.com Unofficial HAMP Loan Modification Calculator html5csv.js Javascript/JQuery lib for manipulating tabular data multicoresql Map/Reduce parallel execution framework for SQL queries. Hobbies: Amateur Radio Callsign KI6CQ
Updated on June 04, 2022Comments
-
Paul almost 2 years
Ubuntu Studio Linux 14.04.1 LTS
From a Linux shell script, I'd like to launch a browser window of an exact size, e.g. as a step for automatically recording a screencast.
My first thought was to use Xwindows
-geometry
setting, which once upon a time was common to all apps in Xwindows and was preserved in Gnome options#!/bin/bash -e chromium-browser -geometry 1280x720 # ignores the spec # firefox -geometry 1280x720 ignores the spec too
I found this post in the FreeBSD forum which also says that firefox ignores the
-geometry
setting. The recommendation was to use Javascript on startup, like this:% firefox javascript:%20resizeTo\(1280,720\)
to call window.resizeTo() in JS. Testing, that doesn't work either. The linked page from MDN notes that with a few exceptions, this will not work post Firefox 7.
@helloV pointed me to: Launch Google Chrome from the command line with specific window coordinates
which is about position not size. Nevertheless, digging through it yielded these ideas that also don't work
NO:
chromium-browser --window-size=800,600 chromium-browser --window-size="800,600" chromium-browser --window-size=800x600 chromium-browser -window-size=800,600 chromium-browser -window-size=800x600
We could always read the Firefox Command Line Options page (hint: window size isn't there) or the Chrome switches source code, where we will find
--window-size=w,h
and that was tried above.From: setting the window dimensions of a running application and a reading of
man xdotool
:This will resize a window after clicking it to select:
xdotool selectwindow windowsize 1280 720
Is there anything simpler or cleaner to start a browser window of specified pixel dimensions?