3

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!

2 Answers2

4

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.

jbrock
  • 3,227
  • 23
  • 33
  • +1 for touch action! This will certainly work. It is less elegant though, because it will add an redundant extra row to my right-click menu (redundant because "create document" is there by default). Are you aware of the direct command (if it exists) to run this without using a custom action? –  Jul 28 '16 at 06:29
  • I found [this](http://docs.xfce.org/faq). Enabling editable menus is great, and it works for almost all menu entries **except** create empty file!! What a shame. –  Jul 28 '16 at 06:47
  • I realized about the duplication on the context menu. I could not find a way around that. – jbrock Jul 28 '16 at 14:10
  • This seems like it would be a good feature request for the Xfce team. If you can create a new directory so easily with a keyboard shortcut, it would make the most sense that you could do the same for a new blank file. – jbrock Jul 28 '16 at 14:11
  • Agree with you. I did that [already](https://bugzilla.xfce.org/show_bug.cgi?id=12732). Thanks! –  Jul 28 '16 at 14:36
  • @luchonacho The file manager PCManFM has this capability. It is fairly similar to Thunar. Ctrl+Alt+N by default creates a plain blank file. The menu item is under File > Create New. – jbrock Oct 15 '16 at 23:02
0

I used jbrock's method with few improvements:

my command:

exo-open --working-directory %f --launch TerminalEmulator "thunar-new && exit"

my script (thunar-new):

#!/bin/bash
echo -n "Enter name: "
read name
touch "$name"    

what it does:

  • on Alt+n, it opens a terminal asking for the name of the new file, and then creates the file with the name in the folder where Alt+n was pressed.

  • you can enter spaces without having to use quotes.

AEM
  • 1,166
  • 2
  • 11
  • 18
  • 1
    Good idea, but you could use a zenity dialog or yad dialog instead of having the user enter the name in a terminal. – vanadium Nov 05 '19 at 10:48