Clear the find fields before searching for more files

When I click 'Find' I often forget to clear the "Containing text" field or the "Date" field. So I made this little app to clear those things. This app clears the Find dialog fields:

  • Containing text
  • Date
  • Time
  • Size
  • Type
  • (Edit 03/27/2009: Version 2.1 — no longer clears the filename field. I found that annoying.)

Concept:

  • Opus9 saves the find dialog data in /DopusLocalData (an Opus9 built-in alias)
  • The concept is to go in there and clear out what we don't want before doing a find. I do that by executing a script before doing the find.

An example for testing purposes:

  1. Place OpusClearFind.exe file in C:\Temp\
  2. Set the Find button command to:
    C:\temp\OpusClearFind.exe {alias|dopuslocaldata|noterm}
    Find
    

Details:

That should be enough info for the expert users. For the less experienced I'll go into some detail here. To edit what the find button does:

  1. Enter Customize mode: SETTINGS -> CUSTOMIZE
  2. Right-click on the button
  3. Select 'Edit'
  4. Select 'Advanced'
  5. Enter the commands:
    C:\Temp\OpusClearFind.ahk {alias|dopuslocaldata|noterm}
    Find
    

Notes on Editing Opus9 Buttons
The above is the method to edit a button that does only one thing. If the button does more than one thing, i.e. right-clicking the button does something else and middle-clicking the button does something else, then to edit that button:

  1. Enter Customize mode: SETTINGS -> CUSTOMIZE
  2. Left-click the button. A menu should drop down.
  3. The menu items are: Left Mouse Button; Right Mouse Button; Middle Mouse Button.
  4. Right-click the menu item you want to edit, and select 'Edit' (I know. I was initially confused too, which is why I detail how to do it here.)

Customizing the App
The source for OpusClearFind.exe is OpusClearFind.ahk . This is an AutoHotKey script file. AutoHotKey is a free and incredibly powerful and useful scripting language (wwww.autohotkey.com). Download and install it. Then you don't need the .exe file, instead use the .ahk file. Specify OpusClearFind.ahk in the Opus find command instead of the .exe version. Then you may modify the OpusClearFind.ahk script to your heart's content. Here's the code:

;CLEAR OPUS9 FILE SEARCH FIELDS (file name, containing, file date, file time, file size)
;Version 2.0 12/31/2008
DopusLocalData = %1%
findosd = %DopusLocalData%\State Data\find.osd

FileRead, Contents, %findosd%
if not ErrorLevel  ; Successfully loaded.
{
    ;;; (don't clear the filename) Contents := RegExReplace(Contents, "<name>.*</name>", "<name />")
    Contents := RegExReplace(Contents, "<contains>.*</contains>", "<contains />")
    Contents := RegExReplace(Contents, "<date_type>.*</date_type>", "<date_type>0</date_type>")
    Contents := RegExReplace(Contents, "<time_type>.*</time_type>", "<time_type>0</time_type>")
    Contents := RegExReplace(Contents, "<size_type>.*</size_type>", "<size_type>0</size_type>")
    Contents := RegExReplace(Contents, "<type>.*</type>", "<type />")
    FileDelete, %findosd%
    FileAppend, %Contents%, %findosd%
    Contents =  ; Free the memory.
}

For example, if you don't want the Opus Find dialog "Name matching:" field to be cleared, just remove the line:

    Contents := RegExReplace(Contents, "<name>.*</name>", "<name />")

(or comment out that line using a semicolon ; Edit 03/27/2009 I commented out this line for version 2.1.)

AutoHotKey notes:
NOTE: In the AutoHotKey scripting language you may also comment out a block of code using / to begin a block and / to end the block. However, the closing */ needs to be the first item on the line! (I've been bit by that which is why I remember that caveat. "Why does the script stop in the middle? It's as if the entire rest of the script was commented out.")

NOTE: To compile a *.ahk file into a *.exe file, just right-click on the .ahk file and select 'Compile Script'

Advanced
I created a special directory for all my AutoHotKey scripts and created an environment variable %AUTOHOTKEY% which points to the directory.

To create an environment variable:

  1. START -> RUN, enter "sysdm.cpl"
  2. 'Advanced' (tab of 'System Properties' dialog)
  3. 'Environment Variables' (button on Advanced tab)
  4. User variables. Click 'New'
  5. Variable name: AUTOHOTKEY
  6. Variable value: C:\Users\Public\_zProgramFiles\AutoHotKey
  7. Reboot. (The variable doesn't take effect until you reboot.)
Then we can set the Opus9 'Find' button to:
%AUTOHOTKEY%\OpusClearFind.ahk {alias|dopuslocaldata|noterm}
Find

Edit 03/27/2009: Commented out the clearing of filename field.

References & notes:

  • The AutoHotKey script above I copied from the example at: autohotkey.com/docs/commands/FileRead.htm
  • (Another scripting program which complements AutoHotKey nicely is KeyText ([www.keytext.com](http://www.keytext.com)) With the two of them combined I can do quite a lot.)
  • I'm only moderately good at Opus so far. Getting better at it. Wasn't sure how much detail I should give here. I took the approach of first giving an overview which gives experienced users all they need to know. Then go into detail for those less experienced who need a bit more detail.
  • I'm not allowed to edit this post after I submit it. If there are any errors in the post just blame them on my dog. I blame everything on my dog. It's very convenient. Dog doesn't seem to notice. Oh, I am allowed to edit my post. That's nice.
  • Our Limited Time Guarantee All programs and utilities are hereby guaranteed to be free from defects in workmanship and programming for a period of one (1) minute after initial release. After that, you must refer below to the fully limited lifetime warranty. This guarantee does not cover damage due to accident, misuse, abuse, negligence, or incompetence. We are not responsible for any incidental or consequential damage which might occur as a result of the explicit or implicit use of these programs, including and not to exclude the possible complete destruction of all software on said machine, including said machine itself, along with the building containing said machine, and various parts of the surrounding country side. This guarantee is valid only in the United States, except for southern California, and only between the hours of 8:00 AM and 5:00 PM whenever we feel like it. Void where prohibited.

    Our Fully Limited Lifetime warranty
    In the event one of our utilities does not function properly due to faulty workmanship or programming logic, we will:

    1. For a period of one month after initial release, we will listen to your complaints and smile politely, occasionally nodding the head as if in agreement.
    2. For a period of one year after initial release, we will supply, at no charge to the user, sympathy and commiseration over any component of a program found to be inadequate.

      This warranty gives you specific rights, and you may have other rights which vary from state to state. i.e. the state (of mind) you are in may affect the intensity of our sympathy.

      (Just joking.)


OpusClearFind2.01.zip (194 KB)

I noticed that the FileDelete line in the Autohotkey script had a hardcoded path to C:\Users\... instead of using %LOCALAPPDATA% like the other lines.

I corrected the script and uploaded a new version of the zip file. (I updated all three places: Root post's code box, .ahk in the zip and .exe in the zip.)

Nice, detailed guide, BTW!

I don't have an environment variable %localappdata%. Is that a Vista addition?

(Yes, I know I can create one).

It might be, yeah.

You can find the appropriate path by typing /dopuslocaldata into the location field in Opus.

%LOCALAPPDATA% is indeed a newish Vista env var...

On XP, you can get the equivalent with %USERPROFILE%\Local Settings\Application Data.

That said, you can probably just do something like:

Delete FORCE QUIET FILE "/dopuslocaldata\State Data\find.osd"

...before all your Find function buttons and hotkeys just within Opus. Then specify the rest of your normally desired 'options' for the find operations as function arguments... i.e:

Delete FORCE QUIET FILE "/dopuslocaldata\State Data\find.osd"
Find COLLNAME "Find Results" SHOWRESULTS tab IN {s}

Just a different way... but for anybody interested in playing with Autohotkey (@Bernard re: coffeeshop post :wink: )... deleyed's way is a nifty example showing some fundamental functions of AHK...!

Matter of fact... I'm definitely going to keep this bound to my <Ctrl+F> hotkey... I've burned myself MANY times after searching for 'containing text' only to want to search for filenames later and have it fail because I hadn't noticed the containing text stuff is still in there. THANKS FOR THE IDEA DELEYED...

EDIT NOTE: FWIW, the find 'history' stuff is stored in a different file(s). So depending on whether you want that stuff to be retained or not, you can check out:

/dopuslocaldata\State Data\find_contains.osd
/dopuslocaldata\State Data\find_name.osd
/dopuslocaldata\State Data\find_path.osd

And probably treat them accordingly...

A neat AHK example.

... and as I recover from Christmas dinner, the humour went down quite nicely too. :smiley:

Thanks.

Released version 2.0
Decided to use the Opus9 alias /DopusLocalData and pass it to the AutoHotKey script, instead of futzing around with %LocalAppData% which doesn't exist in Windows XP.

Released version 2.1
Decided clearing the filename field was annoying. Commented out that line and recompiled.