Creating a file browser for Thunar with Zenity


This article was published a long time ago in my old blog about Xfce, based on another article published in the Xubuntu blog and I leave them here again.

What we are going to do is create a file search for Thunar using zenity. The first thing we have to do is install zenity:

$ sudo aptitude install zenity

Then we open a terminal and put:

$ mkdir ~/.bash-scripts/

In this way we create a directory that will contain the script that will execute the action itself. Now we create a file called Search-for-Files inside as follows:

mousepad ~/.bash-scripts/search-for-files

and we paste this inside:

#! / bin / bash # search-for-files # change this figure to suit yourself - I find zenity dies from about 1000 results but YMMV maxresults = 500 # again, change the path to the icon to suit yourself. But who doesn't like tango? window_icon = "/ usr / share / icons / Tango / scalable / actions / search.svg" # this script will work for any environment that has bash and zenity, so the filemanager is entirely down to you! you can add extra arguments to the string as long as the last argument is the path of the folder you open filemanager = "thunar" window_title = "Search for Files" srcPath = "$ *" if! [-d "$ srcPath"]; then cd ~ / srcPath = `zenity --file-selection --directory --title =" $ window_title - Look in folder "--window-icon =" $ window_icon "` fi if [-d "$ srcPath"] ; then fragment = `zenity --entry --title =" $ window_title - Name contains: "--window-icon =" $ window_icon "--text =" Search strings less than 2 characters are ignored "` if! [$ {# fragment} -lt 2]; then (echo 10 O = $ IFS IFS = $ '\ n' files = (`find" $ srcPath "-iname" * $ fragment * "-printf \"% Y \ "\ \"% f \ "\ \" % k \ KB \ "\ \"% t \ "\ \"% h \ "\\\ n | head -n $ maxresults`) IFS = $ O echo 100 selected =` eval zenity --list --title = \ "$ {# files [@]} Files Found - $ window_title \" --window-icon = "$ window_icon" --width = "600" --height = "400" --text = \ "Search results : \ "--print-column = 5 --column \" Type \ "--column \" Name \ "--column \" Size \ "--column \" Date modified \ "--column \" Path \ "$ {files [@]}` if [-e "$ selected"]; then "$ filemanager" "$ selected"; fi) | zenity --progress --auto-close --pulsate --title = "Searching ..." --window-icon = "$ window_icon" --text = "Searching for \" $ fragment \ "" fi fi exit

and we give it execution permissions:

chmod a+x ~/.bash-scripts/search-for-files

Now we make a backup of the uca.xml file:

$ sudo cp /etc/xdg/Thunar/uca.xml /etc/xdg/Thunar/uca.xml.old

to which we will put at the end this:

<name>Search for Files</name>
<command>bash ~/.bash-scripts/search-for-files %f</command>
<description>Search this folder for files</description>

Now what we have left is to open Thunar » Edit » Set up custom actions and we create a new one. And we fill in the following fields:

In the Basic:
Name: Search
Description: Search
Command: bash ~ / .bash-scripts / search-for-files% f
Icon: We select the one we like the most.

Remaining like this:

Now in the tab Terms of use appearance the following fields:
File Pattern: *
Appears if the selection contains: Directory.

And it looks like this:

Now Thunar When we open the menu with the right click, the search option does not appear:

And if we click on it, a window will appear where we can insert the search criteria:

When we start the search we will see something like this:

and finally the result of it:

If we double-click on the result, a window of Thunar with the folder where the file is located. In this way we give our desktop much more power Xfce.

The content of the article adheres to our principles of editorial ethics. To report an error click here.

9 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Alez said

    What a complication! Hehe, here you have another way to achieve something similar that is easier for me.
    With the fuss of Unity and Gnome3 many people go to Xfce and begin to discover the wonders of Thunar ... Seriously, that program is incredible. Thank you very much for the blog, I follow it regularly even if it is the first time I post.

    1.    elav <° Linux said

      Welcome alez:
      Hahaha it's not that complicated, it's very simple. It is true that with CatFish we can have a powerful search tool, but nothing, at least I do not use it since it is one less application to install 😀

  2.   Oscar said

    Thanks elav, very good tuto, I'm going to save it with the ones you already published, I think XFCE has a lot of future as an alternative, that is, as long as it doesn't run wild in Ram consumption.

  3.   Leodelacruz said

    Very good, to try it 😉

  4.   Matovitch said

    I don't understand Spanish, but I understand bash.
    I Started to Implement The Same Thing. I Saved A Lot of Time Thanks to Your Code.
    Thank you. Thank you. Merci de France.

  5.   Luis said

    There is a big problem with this script ...

    If you do a search for something that is not there then the search engine remains in an infinite loop and the only way to close it is by killing the process.

    1.    Alexander Morales said

      I think the solution in that case would be to make an if that validates if there are no files first, and if there is one that does the search, 😀

  6.   Raul said

    Thank you very much, it really goes a long way and even to create another add-on for thunar.

  7.   Victor said

    I found it excellent. very practical. Thank you so much.