Friday, November 25, 2011

Keyboard shortcut for open terminal here in thunar

Thunar has a right-click custom action, where one open a terminal in the same directory in which one is working. However, I personally miss the option of assigning a keyboard shortcut for the above job (as in pressing ``F4" in konqueror). Work regarding this has already started as said here.
However, until this is implemented directly within thunar, I have written a shell script to do the above job. In other words, keyboard shortcut for opening a terminal in the working directory of thunar is possible now.

Requirements

The following are the requirements which the script depends upon. Install them in ubuntu via apt-get or synaptic.
sudo apt-get install xdotool xclip thunar xfce4-terminal

Installation of script

Download the script from here and rename it ``thunar-terminal.sh". Installation of script is as in installation of most shell script. Make the script executable and move it to your $PATH.
chmod +x thunar-terminal.sh
mkdir -p ~/bin/
mv thunar-terminal.sh ~/bin/

Window manager configuration

This configuration sets ``F4" as the global shortcut. However, the shortcut works only if Thunar window is active. Otherwise, nothing happens.
I work in Openbox window manager with Thunar as file-manager. So I can only talk about keyboard configuration of openbox. However, any window/desktop manager worth it's salt usually allows its users to configure global keyboard shortcuts.
The keyboard configuration for openbox is as follows. Open the file ~/.config/openbox/rc.xml and copy these lines under
<!-- Keybindings for running applications -->
<keybind key="F4">
      <action name="execute">
        <execute>thunar-terminal.sh</execute>
      </action>
    </keybind>
Now logout and login.

Thunar configuration

Thunar also requires a bit of configuration. I have noticed that the script works best if ``Location Selector" of thunar is in ``Toolbar Style". To select the ``Toolbar Style" of Thunar $ >$ View $ >$ Location Selector $ >$ Toolbar Style.
Now press ``F4" and watch as the xfce4-terminal opens in the working directory of Thunar.

6 comments:

  1. This is tinkering, but it works, thank you !

    ReplyDelete
  2. But only if the PATH variable contains the folder ~/bin/, otherwise we must add them or put the file in thunar-terminal.sh /usr/bin.

    ReplyDelete
  3. This was THE THING keeping me from using thunar (now that they added tab support). Your workaround makes it perfect. Thanks a lot for this very useful solution, and also for your clear explanation.

    ReplyDelete
  4. If you move the `Location = $(xclip -o) ` command between the Ctrl-c and the return then your method will become compatible for both with the PathBar and ToolBar Style.

    Works great with the --drop-down option of xfce4-terminal.

    Great work!

    ReplyDelete
  5. Thanks :)

    Takes lesser time than Custom Actions :D

    P.S. Configured it with XFCE4, Keyboard Shortcuts, and --drop-down :P

    Awesome!

    ReplyDelete
  6. Hi there, I'm trying to get this going using Thunar 1.6.3, but no success so far. The terminal opens but only in my home directory no matter from which directory within thunar I'm calling the script.

    ReplyDelete