How to start nautilus maximized from command line?

Nicolas Raoul

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.

Jacob Vlijm

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Resizing a maximized window from the command line

From Dev

How to open a nautilus directory and select a file in it from the command line?

From Dev

How to open Nautilus in a specified directory from the command line?

From Dev

How can I initiate Nautilus file operations from the command line?

From Dev

How can remote host be mounted with nautilus from command line to avoid opening a nautilus window?

From Dev

How to start GUI from command line?

From Dev

How to start CouchDB from command line

From Dev

How to start GUI from command line?

From Dev

How to start Pantheon from the command line

From Dev

How to start CouchDB from command line

From Dev

Directory created from command line not appearing in Nautilus

From Dev

How to start gVim maximized?

From Dev

How to start and run a command from git from Command Line

From Dev

How to open Nautilus at current command line directory?

From Dev

How to open Nautilus at current command line directory?

From Dev

How to start line with command from output of another command

From Dev

getty start from command line?

From Dev

How to start Putty in a maximized window?

From Dev

How to start Putty in a maximized window?

From Dev

How to start GUI linux programs from the command line, but separate from the command line?

From Dev

CentOS 7 how to stop / start Gnome desktop from command line

From Dev

How to start gnome-wayland session from command line?

From Dev

How to start Tomcat 7 from Windows command line in the same window?

From Dev

How to start Microsoft Edge in InPrivate mode from command line

From Dev

How do I start the Privacy and Activity Manager from command line?

From Dev

How to build and start a windows 8 metro app from the command line

From Dev

How to start Xamarin-Android-Player from command line?

From Dev

How to start MingW Console (GitBash) from Command Line on Windows?

From Dev

How can I start octave from the command line and not the GUI?

Related Related

  1. 1

    Resizing a maximized window from the command line

  2. 2

    How to open a nautilus directory and select a file in it from the command line?

  3. 3

    How to open Nautilus in a specified directory from the command line?

  4. 4

    How can I initiate Nautilus file operations from the command line?

  5. 5

    How can remote host be mounted with nautilus from command line to avoid opening a nautilus window?

  6. 6

    How to start GUI from command line?

  7. 7

    How to start CouchDB from command line

  8. 8

    How to start GUI from command line?

  9. 9

    How to start Pantheon from the command line

  10. 10

    How to start CouchDB from command line

  11. 11

    Directory created from command line not appearing in Nautilus

  12. 12

    How to start gVim maximized?

  13. 13

    How to start and run a command from git from Command Line

  14. 14

    How to open Nautilus at current command line directory?

  15. 15

    How to open Nautilus at current command line directory?

  16. 16

    How to start line with command from output of another command

  17. 17

    getty start from command line?

  18. 18

    How to start Putty in a maximized window?

  19. 19

    How to start Putty in a maximized window?

  20. 20

    How to start GUI linux programs from the command line, but separate from the command line?

  21. 21

    CentOS 7 how to stop / start Gnome desktop from command line

  22. 22

    How to start gnome-wayland session from command line?

  23. 23

    How to start Tomcat 7 from Windows command line in the same window?

  24. 24

    How to start Microsoft Edge in InPrivate mode from command line

  25. 25

    How do I start the Privacy and Activity Manager from command line?

  26. 26

    How to build and start a windows 8 metro app from the command line

  27. 27

    How to start Xamarin-Android-Player from command line?

  28. 28

    How to start MingW Console (GitBash) from Command Line on Windows?

  29. 29

    How can I start octave from the command line and not the GUI?

HotTag

Archive