I tried to use Docky, then I removed it and after that my browser (Chromium) can't be opened in maximum height, every time I should maximize it myself. (XFCE desktop)
1 Answer
How to startup an application (any) maximized
Starting an application via the script below, you can force any application*
to startup maximized. If you either replace the main command in (a copy of-) your .desktop
file by the command to run the script (see further below how to do that) or add it as a quicklist shortcut, you can achieve exactly what you want.
(*
Some applications have a fixed, unchangeable windowsize, some windows open a new tab in a possibly already opened window)
About the script
The script runs with the command:
python3 /path/to/script <application>
The script:
- first runs the command to open the application
- to prevent timing issues, it then waits for the application's (new) window to appear (by finding a match between its
pid
and theid
of the corresponding window) in the output of thewmctrl -lp
-command (for only 15 seconds, to prevent an infinite loop) Once the window appears, it maximizes the window with the command:
xdotool windowsize <window_id> 100% 100%
The code
#!/usr/bin/env python3
import subprocess
import getpass
import time
import sys
app = sys.argv[1]
user = getpass.getuser()
get = lambda x: subprocess.check_output(x).decode("utf-8")
ws1 = get(["wmctrl", "-lp"]); t = 0
subprocess.Popen(app)
while t < 30:
ws2 = [(w.split()[2], w.split()[0]) for w in get(["wmctrl", "-lp"]).splitlines() if not w in ws1]
procs = sum([[(w[1], p) for p in get(["ps", "-u", user]).splitlines() \
if app[:15].lower() in p.lower() and w[0] in p] for w in ws2], [])
if len(procs) > 0:
subprocess.call(["xdotool", "windowsize", "-sync", procs[0][0] , "100%", "100%"])
break
time.sleep(0.5)
t = t+1
How to use
The script needs both
wmctrl
andxdotool
sudo apt-get install wmctrl xdotool
Copy the script above into an empty file, save it as
run_maximized.py
Now edit your
.desktop
file:Copy the global
.desktop
file locally:cp /usr/share/applications/chromium-browser.desktop ~/.local/share/applications
XFCE version:
open the file with gedit:
gedit ~/.local/share/applications/chromium-browser.desktop
Browse to the line:
Exec=chromium-browser %U
(which is the first line, starting with
Exec=
Change it into:
Exec=python3 /path/to/script.py chromium-browser
where you need to replace
/path/to/script.py
by the actual path.Log out and back in. From now on, your Chromium launcher will open Chromium maximized.
Unity version:
open the file with gedit:
gedit ~/.local/share/applications/chromium-browser.desktop
Browse to the line:
Actions=NewWindow;Incognito;TempProfile;
Change it into:
Actions=NewWindow;Incognito;TempProfile;divider1;Open maximized;
The add to the very bottom of the file the section below:
[Desktop Action Open maximized] Name=Open maximized Exec=python3 /path/to/script.py chromium-browser OnlyShowIn=Unity; [Desktop Action divider1] Name=..................................... OnlyShowIn=Unity;
where you need to replace
/path/to/script.py
by the actual path.Log out and back in. From now on, your Chromium launcher looks like:
Important note
In a .desktop
file, you must use absolute paths; ~
won't work for example. This counts for .desktop
files in /usr/share/applications
, ~/.local/share/applications
as well as commands in Startup Applications (which are actually called by .desktop
files in ~/.config/autostart
).
-
-
I tried to do it with Thunar - didn't work: I edited /usr/share/applications/Thunar.desktop, changed this line: Exec=python3 ~/script.py thunar %F– R SNov 18, 2015 at 1:19