Keyboard shortcut to create a new empty file on Ubuntu 18.04

Solution 1:

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.