1

What is the shortcut for opening a new window (opening folders). for that I have to go to folder options and right click and then need to click on open new window.

or I have to make focus on the folder icon or open a folder then press

Ctrl+N

for opening a new window is there any direct command spcific to open a new window in ubuntu.

  • Are you talking about Nautilus, the default Ubuntu (Unity) file browser? – Sparhawk Aug 7 '14 at 6:02
  • yes ,the default Ubuntu file browser – Ali786 Aug 7 '14 at 6:08
3

To open a general window (12.04 / 14.04+)

I assume you would like to have a key combination to open a new Nautilus window (and raise it), no matter what application is in front.

You can do that, using a small script and adding a key combination to your shortcuts to run it.

  • If not installed, install wmctrl:

    sudo apt-get install wmctrl
    
  • Save the script below as "new_window" and make it executable. The script has a small difference for 14.04 or 12.04:

For 12.04:

#!/usr/bin/env python
import subprocess
import socket

def read_windowlist():
    get_pid = subprocess.Popen(["wmctrl", "-l", "-p"], stdout=subprocess.PIPE)
    wlist = [(item[14:21].split(" ")[0], item.split(socket.gethostname()+" ")[-1]) for item in get_pid.communicate()[0].decode("utf-8").split("\n")]
    return wlist

def read_pid():
    get_pid = subprocess.Popen(["pidof", "nautilus"], stdout=subprocess.PIPE)
    return get_pid.communicate()[0].decode("utf-8").replace("\n", "")

def find_window():
    nautilus_window = [item for item in read_windowlist() if item[0] == read_pid()][-1]               
    subprocess.Popen(["wmctrl", "-a", nautilus_window[1]])
    subprocess.Popen(["nautilus"])

find_window()

For 14.04+:

#!/usr/bin/env python3
import subprocess
import socket

def read_windowlist():
    get_pid = subprocess.check_output(["wmctrl", "-lp"]).decode("utf-8").split("\n")
    return [(item[14:21].split(" ")[0], item.split(socket.gethostname()+" ")[-1]) for item in get_pid]

def read_pid():
    get_pid = subprocess.Popen(["pidof", "nautilus"], stdout=subprocess.PIPE)
    return get_pid.communicate()[0].decode("utf-8").replace("\n", "")

def find_window():
    nautilus_window = [item for item in read_windowlist() if item[0] == read_pid()][-1]                       
    subprocess.Popen(["wmctrl", "-a", nautilus_window[1]])
    subprocess.Popen(["nautilus", "--new-window"])

find_window()

Now add a command and a key combination of your preference to run the script (System Preferences > Keyboard > Shortcuts > Custom Shortcuts)

The commmand:

/path/to/script/new_window (don't forget to make the script executable)

Open a new window in a specific directory (14.04+)

To open a specific directory in nautilus on top of everything, call the small script below to open the directory (under your key combination) with the directory as an argument, so that instead of using the command:

nautilus <directory>

to open the directory, you can use the command:

python3 <script> <directory>

How to use
This script also uses wmctrl. To install it:

sudo apt-get install wmctrl

The script

#!/usr/bin/env python3

import subprocess
import sys

window = sys.argv[1]

subprocess.call(["nautilus", window])
wname = '"'+window.split("/")[-1]+'"'
subprocess.Popen(["wmctrl", "-a", wname])

Copy it into an empty file, save it as raise_nautilus.py and run it by the command:

python3 /path/to/raise_nautilus.py </path/to/folder/to/open>

*Note: if your directory contains spaces, use quotes around it.

  • do i need to install python lib – Ali786 Aug 7 '14 at 11:34
  • okay ..I just going to finished but stopped. – Ali786 Aug 7 '14 at 11:41
  • thats ok sir I will also test. – Ali786 Aug 7 '14 at 12:05
  • @ali786 ..You must have forgotten to install wmctrl (sudo apt-get install wmctrl) like I did on my second 12.04 machine :). I just tried on a 15 minutes old 12.04 install, and it works well. – Jacob Vlijm Aug 7 '14 at 20:25
  • ,Should I go for installing this... – Ali786 Sep 9 '14 at 4:16
6

By default, the keyboard shortcut to launch the file browser is the special key Explorer, available on some keyboards (along with other special keys to laucnh music players, internet browsers and so on). You can change this to something else in the Shortcuts section of Keyboard settings:keyboard shortcut screenshot Change the Home folder shortcut to something else.

  • 1
    If I understand the question correctly, what @Sparhawk is looking to do is the equivalent of Right-click>Files>Open a New Window - particularly where a window may already be open. What (if any) is the shortcut for that (or a suitable Custom Shortcut)? – Graham Aug 7 '14 at 8:22
  • 1
    @NoviceUserFrance That would require focusing the window in question, if you want a copy of a window opened to particular folder, I think (or add a custom shortcut with command /usr/bin/nautilus /path/to/folder/. I don't really understand - right click what? The icon in the launcher? If so, that opens a new window with the home folder, I think, which is what this keyboard shortcut does. – muru Aug 7 '14 at 8:26
  • 1
    I think that's what the OP wants, the ability to open a new 'file window' when the focus is already on another 'file window' and yes, right click the Files icon in the launcher then select Open a New Window. If I have a 'file window' open, using my shortcut only refocuses on the already open window and doesn't open a new window. – Graham Aug 7 '14 at 8:35
  • 2
    @NoviceUserFrance in which case the OP has already given the solution: Ctrl-N. It looks to me that OP only wants to open a new window, irrespective of the path. The keyboard shortcut mentioned in the answer always opens a new window to the home folder. – muru Aug 7 '14 at 8:37
  • Quite right, thanks for that. I hadn'y appreciated that Ctrl-N works where the focus is already on an open window. Your answer then seems to fit the requirement admirably and works well for me. – Graham Aug 7 '14 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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