Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can easily start Nautilus on a particular directory from command line:

nautilus /home/nico/Documents

But I want that Nautilus window to be maximized.
How to write the command line?

nautilus does not seem to recognize --maximized nor --fullscreen. I reluctantly tried --geometry 1500x1500 and it does seem to have any effect.

share|improve this question
1  
Hi Nicolas, it can be done, but needs a tiny script. Will post in 20 minutes (I guess). – Jacob Vlijm Jan 19 at 8:09
    
for me with resolution at 1280x1024: 'nautilus --geometry=1280x1024' launch it fullscreen as a charm. :-/ – gentooza Jan 19 at 8:21
up vote 6 down vote accepted

1. Start up nautilus with a maximized window

To start nautilus with a maximized window, you can use the script below:

#!/usr/bin/env python3
import subprocess
import time
import sys

def w_list():
    try:
        pid = subprocess.check_output(["pgrep", "nautilus"]).decode("utf-8").strip()
        w_list = subprocess.check_output(["wmctrl", "-lp"]).decode("utf-8").splitlines()
        return [l.split()[0] for l in w_list if pid in l]
    except subprocess.CalledProcessError:
        pass

relevant1 = w_list()
subprocess.Popen(["nautilus", "--new-window"])

t = 0
while t < 30:
    time.sleep(0.5)
    relevant2 = w_list()
    if all([relevant2 != None, relevant1 != None]):
        new = [w for w in relevant2 if not w in relevant1]
        if new:
            subprocess.Popen(["xdotool", "windowsize", new[0], "100%", "100%"])
            break
    relevant1 = relevant2
    t += 1

How to use

  • The script uses both xdotool and wmctrl, the first one to list new windows of the targeted application, the last one because I prefer the way xdotoolresizes windows.

    sudo apt-get install xdotool wmctrl
    
  • Then copy the script above into an empty file, save it as start_maximized.py

  • Test- run the script by the command:

    python3 /path/to/start_maximized.py
    

    Now nautilus will start up with a new maximized window.

  • Add, if you like, the command as a quicklist (right- click) item to the Files (nautilus) launcher in the Unity Launcher.

2. Generalized version; start up any application maximized

You can startup any GUI application (+ their arguments) in the generalized script below:

#!/usr/bin/env python3
import subprocess
import time
import sys

appcommand = sys.argv[1:]
app = appcommand[0]
startup = (" ").join(appcommand)

def w_list():
    try:
        pid = subprocess.check_output(["pgrep", app]).decode("utf-8").strip()
        w_list = subprocess.check_output(["wmctrl", "-lp"]).decode("utf-8").splitlines()
        return [l.split()[0] for l in w_list if pid in l]
    except subprocess.CalledProcessError:
        pass

relevant1 = w_list()
subprocess.Popen(["/bin/bash", "-c", startup])

t = 0
while t < 30:
    time.sleep(0.5)
    relevant2 = w_list()
    if all([relevant2 != None, relevant1 != None]):
        new = [w for w in relevant2 if not w in relevant1]
        if new:
            subprocess.Popen(["xdotool", "windowsize", new[0], "100%", "100%"])
            break
    relevant1 = relevant2
    t += 1

To use it

  • Do the setup exactly as above (including installing wmctrl and xdotool, but additionally use the targeted application (+ possible arguments) as an argument to run the script.

    For example:

    python3 /path/to/start_maximized.py nautilus --new-window
    

    or:

    python3 /path/to/start_maximized.py gedit
    

Additionaly, add the option to a quicklist

enter image description here

You can easily add the option to the nautilus quicklist. Assuming you use the second (generalized) version:

  • Copy the global nautilus.desktop file locally:

    which is on 14.04 and 14.10 : nautilus.desktop:

    cp /usr/share/applications/nautilus.desktop ~/.local/share/applications
    

    and on 15.04 and 15.10 : org.gnome.Nautilus.desktop

    cp /usr/share/applications/org.gnome.Nautilus.desktop ~/.local/share/applications
    
  • Open the file with (e.g.) gedit, look for the line:

    Actions=Window;
    

    Change it into:

    Actions=Window;Open a maximized window;
    

    Add to the very end of the file:

    [Desktop Action Open a maximized window]
    Name=Open a maximized window
    Exec=python3 '/path/to/start_maximized.py' nautilus --new-window
    OnlyShowIn=Unity;
    
  • Save and close the file.

  • Log out and back in.

Now you have a quicklist option like in the image.

Conceptual explanation

To maximize an existing window is not very difficult. Both wmctrl and xdotool offer options to do so.

The issue is that if you want to maximize a newly created window, you don't know the window id yet when you give the command. Therefore the script practices the following procedure:

  1. make a list of the currently existing windows of the targeted application (if any)
  2. give the command to open the application (or a new window of a running application)
  3. keep an eye on new windows of the application to appear
  4. if the new window appears, it is apparently our candidate to maximize -> maximize it.

This way, we can "smartly" maximize the application's new window, that will work no matter the computer is slow (occupied with a heavy job for example) or fast.

Finally, the script has a built in safety time-limit, to prevent waiting for ever in case the application fails to start up for some reason. After appr. 15 seconds, the script gives up and exits an way.

share|improve this answer
    
python3 /home/nico/p/start_maximized.py nautilus --new-window gives me FileNotFoundError: [Errno 2] No such file or directory: 'wmctrl' at line 18. – Nicolas Raoul Jan 19 at 9:20
1  
+1 This works great for me :) @NicolasRaoul sudo apt-get install xdotool wmctrl is required to run the script. – Mark Kirby Jan 19 at 9:22
1  
+1, great sollution :-D – gentooza Jan 19 at 9:27
1  
Sorry I had forgotten to install these packages, it works great now! – Nicolas Raoul Jan 19 at 9:30
    
@NicolasRaoul perfect, glad it works :) I will add some explanation. – Jacob Vlijm Jan 19 at 9:36

Nautilus remembers the windows size.
Start it normally and maximize it, then close it.

Now when you type nautilus in terminal, it will open up maximised.
Tested on Ubuntu 14.04 LTS.

share|improve this answer
    
Oh, so there is no way to only sometimes launch it maximized, but the rest of the time at a smaller size, right? Thanks! – Nicolas Raoul Jan 19 at 7:58
    
@NicolasRaoul Am not sure. Unless you target specific nautilus windows using compiz. – Parto Jan 19 at 8:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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