While I have a nautilus window open I can do Ctrl+Shift+N to create a new folder in the current directory. However there is no default keyboard shortcut for creating a new document. How would I create one?
nautilus – How to Create a ‘New Document’ Keyboard Shortcut
nautilusnautilus-elementary
Related Solutions
Finally figured it out.. first sudo apt-get install dconf-tools nautilus-open-terminal
, then run dconf-editor
and set the org/gnome/desktop/interface/can-change-accels
boolean on. Then open nautilus using this command (to disable Unity global menu Temporarily):
nautilus -q
UBUNTU_MENUPROXY=0 nautilus
Now you can mouseover the action in the file menu, and change the accel by typing your key while the action is highlighted, finally restart your nautilus. If you don't see Open in terminal in the File menu and you've just installed nautilus-open-terminal
, you might need to first run nautilus -q
.
Ubuntu 14.04 and up
If you can't find the can-change-accels
key in your dconf configuration you can try the following solution:
- Stop nautilus by executing
nautilus -q
Open
~/.config/nautilus/accels
in a text editor of your choice, e.g. gedit:gedit ~/.config/nautilus/accels
Try to see if you can find the following line:
;(gtk_accel_path "<Actions>/DirViewActions/OpenInTerminal" "")
If the line exists, add your keyboard shortcut in the second double-quoted segment and uncomment the line by removing
;
:(gtk_accel_path "<Actions>/DirViewActions/OpenInTerminal" "F12")
This would set the shortcut to F12. For a list of all possible key codes please consult this answer.
If the line doesn't exist just copy and paste the one found in this answer at the end of the file.
Save the file and restart Nautilus by clicking on the Nautilus icon in your launcher/dash.
Ubuntu 15.10 and 16.04
Here, the relevant command in ~/.config/nautilus/accels
is TerminalNautilus:OpenFolderLocal
. (NautilusOpenTerminal::open_terminal
is still present in the file, but doesn't seem to have any effect.) So follow the instructions above, except change the line
; (gtk_accel_path "<Actions>/ExtensionsMenuGroup/TerminalNautilus:OpenFolderLocal" "")
to
(gtk_accel_path "<Actions>/ExtensionsMenuGroup/TerminalNautilus:OpenFolderLocal" "F12")
to make F12 your keyboard shortcut. Notice that ;
is again removed.
Finally, log out for changes to take effect.
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.
Best Answer
First, open gconf-editor and set
/desktop/gnome/interface/can_change_accels
totrue
. This lets you edit menu shortcuts.Second, open a terminal and type:
killall nautilus && UBUNTU_MENUPROXY= nautilus
This will relaunch Nautilus with the standard (non-Unity) menu bar, because the Unity menu bar doesn't support this feature. (It will respect your changed shortcuts, but it won't let you change them.)Now, open the file menu, hover the mouse over Create Document > Empty File and press your desired shortcut. Ctrl-Alt-N seems like a decent choice, or you can reassign Ctrl-N. You should see the accelerator hint change in the menu.
Finally, relaunch Nautilus without the
UBUNTU_MENUPROXY
variable to get your Unity menus back with the new shortcut.Edit: The solution for newer versions is nearly the same , except you need to use
dconf-editor
instead ofgconf-editor
. You can install thedconf-tools
package to get dconf-editor.Also, the
killall nautilus ...
command did not appear to be necessary.org/gnome/desktop/interface
.can-change-accels
.can-change-accels
in dconf-editor after you're done.