3

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?

Community
  • 1
  • 1
Paul
  • 26,170
  • 12
  • 85
  • 119
  • [Possible duplicate?](http://stackoverflow.com/questions/13436855/launch-google-chrome-from-the-command-line-with-specific-window-coordinates) – helloV Nov 23 '14 at 05:23
  • @helloV No, thats position, not size. Selected answer won't do it, the one with 5 upvotes might have something useful in it. A direct answer might be possible from going through some of the links. – Paul Nov 23 '14 at 05:27
  • @helloV Thanks for the link. I'm less hopeful now after reading through the links and seeing `--window-size` and variants don't work. – Paul Nov 23 '14 at 05:39

3 Answers3

5

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`
Duffydake
  • 917
  • 7
  • 18
  • I appreciate the effort, not quite what I wanted. Would be better if there was a way to mark the browser window when starting it. We can easily know the pid when starting the browser... Can a wid be looked up by process id (pid)? – Paul Nov 23 '14 at 14:06
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". ↪

sabueso
  • 21
  • 1
0

command: firefox -width xxx -height yyy -P profile

It works for me on condition I specify a profile on the command (-P ppp).

jwvh
  • 50,871
  • 7
  • 38
  • 64