Ubuntu – Add keyboard shortcut to function inside Thunar

shortcut-keysthunarxfce

I am trying to create a keyboard shortcut for "Create document…" subcomponent "Empty file", shown in the picture below:

enter image description here

It seems all the shortcuts in use by Thunar are stored in the file ~/.config/Thunar/accels.scm.

Thus, I tried to create one myself by adding one of the following lines:

(gtk_accel_path "<Actions>/ThunarStandardView/create-archive" "<Primary>n")
(gtk_accel_path "<Actions>/ThunarActions/Tap::create-archive" "<Primary>n")

but none of them work. Any idea which is the correct configuration?

Update: this website shows that it is possible to edit Menu keyboard shortcuts in a very simple fashion (just highlighting a menu entry and pressing a keyboard key(s)). Sadly enough, Empty File is one of the few that do not work this way!

Best Answer

This is possible via Thunar Custom Actions. In Thunar, go to Edit > Configure custom actions.

Add a new custom action:
- Name: Your preferred name
- Description: Your preference
- Command: touch New-File

Under the Appearance Conditions tab:
- File Pattern: *
- Only check: Directories

In terminal run:

cat ~/.config/Thunar/uca.xml

The new custom action you created will be at the bottom. Copy the unique-id.

Open ~/.config/Thunar/accels.scm in your favorite text editor. Search for your unique id you just copied. (You may need to quit Thunar with the command thunar -q and reopen it for the unique id to appear.) Add in your keyboard shortcut as seen in the example below, and uncomment by removing the semicolon at the beginning of the line.

(gtk_accel_path "<Actions>/ThunarActions/uca-action-1469642461001634-1" "<Alt>n")

(I noticed that "<Primary>n" is already used for a new window. You may want to use something else.)

The main drawback with this method is that it does not initialize with the rename dialog box. Also if you wish to create more than one blank file in a row it does not work. To fix that you'd want to create a script with a command such as touch "new-file-$(date +%N)" that generates a random name. Pasting this command directly into the Command box in Thunar Custom Actions does not work because it conflicts with its own command parameters. So instead you'd run your script.