I was wondering whether there is a possibility to assign a keyboard shortcut for creating a new empty file in Ubuntu 18.04 for nautilus. Namely if there is a possibility to assign a keyboard shortcut to the "Empty File" option generated by the right mouse click. The solution provided on this answer does not appear to work for Ubuntu 18.04
-
You just want a shortcut to quickly create an empty file? Or do you want a keyboard shortcut that shows the New Documents menu? Can help you with the former, not with the latter. – vanadium Dec 06 '19 at 17:36
-
I want a shortcut to quickly create an empty file. Thank you for the reply @vanadium – Giannis Pappas Dec 06 '19 at 22:19
2 Answers
Nautilus unfortunately does not allow the user to assign keyboard shortcuts to functions, as in the old days. Still, there is a workaround to create your own hotkeys through the use of nautilus scripts, which can be assigned a hotkey.
You can create a shortcut key to quickly create an empty file as following.
1) Create a nautilus script that does what you want
a) Create the scripts folder if it does not exist
If the folder scripts
does not yet exist in the folder .local/share/nautilus/scripts
, then create it first. .local
is a hidden folder in your home folder. Press Ctrl+h to toggle the display of hidden files in the file manager.
b) Create a new script
Then create a script file in the nautilus scripts folder with the following command.
gedit "/home/$USER/.local/share/nautilus/scripts/New Empty File"
You can leave $USER
: it should normally automatically be substituted with your login name.
The script could look like:
#!/bin/bash
cp "/home/$USER/Templates/Empty Text Document.txt" .
Also this nautilus script will recognize the variable $USER
. Alternatively, replace the variable by your own login name.
c) Make the script executable
Make the script file executable (Right-click, properties or chmod +x "/home/$USER/.local/share/nautilus/scripts/New Empty File"
2. Testing the script
Close Files fully and restart it. To make sure it is fully closed, use the command
killall nautilus
After restarting, you should have a new entry "New Empty File" in your right-click menu when a file is selected.
Assign a hotkey to your script
Edit 2020-11-17 Unfortunately, this seems broken in Files 3.38.1 that comes with Ubuntu 20.10.
Creating a new file with the right-click menu is easy enough without the script. However, the reason we do this is to be able to assign a hotkey. For that, create a file scripts-accels
under .config/nautilus
gedit /home/$USER/.config/nautilus/scripts-accels
Suppose we want to use Ctrl+Shift+t as the shortcut key. Then, the file should contain at least the last line from the following snippet:
; Commented lines must have a space after the semicolon
; Examples of other key combinations:
; <Control>F12 Terminal
; <Alt>F12 Terminal
; <Shift>F12 Terminal
<Control><Shift>t New Empty File
Bonus tip
You can give your new menu entry in the Scripts menu an accelerator, by prepending the script name with _
. The letter prepended by _
will show up with an underscore. This way, a script named "_New Empty File" can be summoned from the keyboard as (a file must be selected) Shift+F10sn.

- 88,010
-
-
I have only 13 reputation so I cannot upvote the answer but I will mark it as solved! :) – Giannis Pappas Dec 08 '19 at 18:11
-
Thank you. It would be better if one could assign keyboard shortcuts to any function, but unfortunately it does not work like that. – vanadium Dec 08 '19 at 18:30
-
I don't know why but in Ubuntu 20.04 combinations with a letter such as t do not seem to work. The combinations with F12 do work. – Kvothe Nov 17 '20 at 15:33
The solution above is almost perfect. Unfortunately the script is copying a new empty file and it is overwriting the file in a given directory if one exists under the same name. This is potentially dangerous.
To overcome it the script should be:
#!/bin/sh
cp --backup=t "/home/$USER/Templates/newfile" .

- 53