How to: Search for files with Thunar

July 12, 2006 at 9:39 am | Posted in scripts, tips and tricks, xubuntu | 14 Comments

At long last! Using this, you can right-click anywhere on Thunar and search for files. You can also run it by itself (by running bash ~/.bash-scripts/search-for-files).

1) Open up the terminal (Xfce menu > System > Terminal). First, we make a place for the script to stay. Then, we edit the script:

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

2) Paste the following into the file, and save it. (You can change the options at the top if you wish.)

#!/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

3) Make it so that Thunar is able to run the script:

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

4) You need to put this script within Thunar’s right-click menu. Paste the following code into the terminal in order to backup the menu config and edit the current one.

cp ~/.config/Thunar/uca.xml ~/.config/Thunar/uca.xml.old ; mousepad ~/.config/Thunar/uca.xml

5) Scroll to the end of the file. Before where it says , paste in the following:

<action><icon>/usr/share/icons/Tango/scalable/actions/search.svg</icon><name>Search for Files</name><command>bash ~/.bash-scripts/search-for-files %f</command><description>Search this folder for files</description><patterns>*</patterns><directories/></action>

Save and exit.

6) To use it, open up Thunar, right click, and click on Search for Files. Type in a filename to search, and click Ok. A list of files will show up; clicking on one of them will show the directory the file is found in.

(Credit goes to lapsey at http://ubuntuforums.org/showthread.php?t=214059)

14 Comments »

RSS feed for comments on this post. TrackBack URI

  1. This isn’t working for me. Also, in your step 5 you’re missing a word or something. Should it state:, “Before where it says MISSING PHRASE HERE,” so i don’t know where I am suppose to paste in your long command. Also, I tried making my own permanent delete click but it just doesn’t show up in the right click menu? I used the “create custom action” in thunar edit menu but that doesn’t show up either. Can you help? I am going to go check the thread that you gave the credit to and hopefully someone else had soem same problem as me and there is a fix.

  2. It didn’t work for me either. The explanation is confusing.

  3. Yeah, a bit got chopped off there when I edited the post. These days it’s a lot easier to just install catfish and use that.

  4. easy way from me:
    1) install catfish from repsitory
    2) after that, open up Thunar and klick Edit
    3) chose Configure custom actions
    4) add a new cutom actions
    5) -Name= search file
    -Description= as you like
    -Command= /usr/bin/catfish –path %F
    -icon= as you like
    6) on Appearance Conditions tab, check Directories

    that’s it now you can search file on any place in thunar

    sorry if my english bad
    I hope you not confuse for my explanation
    cause I just want to share

    • On line: “-Command= /usr/bin/catfish –path %F”
      Do I enter this text as is or instead of “-path %F” I right the folder?

  5. […] Este sencillo tutorial lo he encontrado en el blog de Xubuntu y lo traduzco para ustedes. La idea es que cuando estemos en un directorio dentro de Thunar, en el […]

  6. works for me! on Debian Lenny
    there is really a missing phrase
    Before the closing tag paste in the following script

    /usr/share/icons/Tango/scalable/actions/search.svg
    Search for Files
    bash ~/.bash-scripts/search-for-files %f
    Search this folder for files
    *

  7. Terrible! my last comment is not the text I wanted to write to you! It was accepted as something like html script and totally destroyed!

  8. […] publiqué hace mucho tiempo en mi antiguo blog sobre Xfce, basado en otro artículo publicado en el blog de Xubuntu y se los dejo nuevamente […]

  9. I changed the code slightly to accommodate the use of Yad, just rename zenity to yad, also a small portion of the script, change this line

    if [ -e “$selected” ] ; then “$filemanager” “$selected” ; fi

    to this

    if [ -e “${selected%|}” ] ; then “$filemanager” “${selected%|}” ; fi

  10. Hmmm, my previous post the quotes in the code didn’t show correctly the one’s in the square brackets did thought, I’ll try again, if this don’t work do it manually, don’t cut’n’paste.

    if [ -e "${selected%|}" ] ; then "$filemanager" "${selected%|}" ; fi 

  11. Good commentary . Incidentally , if your company need to merge two PDF files , my husband came across a tool here http://goo.gl/QhiENk.

  12. […] hace mucho tiempo en mi antiguo blog sobre Xfce, basado en otro artículo publicado en el blog de Xubuntu y se los dejo nuevamente […]

  13. Thank you…thank you so much!

    Not sure why this isn’t an option out of the box for Thunar. Either way, thanks!


Leave a comment

Create a free website or blog at WordPress.com.
Entries and comments feeds.