topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 6:27 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Proof of Concept: using files to expose information to FARR  (Read 8119 times)

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
I was going to post a new version of SwitchToTask here until Vitalyb's excellent FARRAltTab was released.  So instead this post is about 'how to expose information to FARR using plain text files and aliases'. I still think the process I used could be beneficial to others, especially Autohotkey coders wanting to use write for FARR. ;)

swexample.png

All source files are enclosed at the end of the post.

THE TECHNIQUE

As FARR can show a list of results for certain files in a folder, it was a logical experiment to see if I could write out information to text files. By using aliases I can then create a command only to query those text files. The result can be passed on to a helper program to process the information.

It turns out this works and I used the technique in a SwitchToTask implementation. Using an autohotkey script when indexing it writes all windowtitles to textfiles in its folder. We can then query the windowtitles using farr and send the result to another helper script that switches to the window chosen.


INDEXING WINDOW TITLES

We use a simple script to index window titles. First we setup the program and remove all previous window titles before indexing.

Code: Autohotkey [Select]
  1. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2.  
  3. ; setting variables
  4. Storage = %A_ScriptDir%
  5. FileDelete , %Storage%\*.txt
  6. Titles =
Then we get a list of all process ids and for each id we get a window title. We remove empty titles and ids and then write the title as the filename part of the textfile:
Code: Autohotkey [Select]
  1. WinGet, id, list,,, Program Manager ; get list of all foreground ids
  2. Loop, %id%
  3. {
  4.         this_id := id%A_Index%
  5.         WinGet, this_process, ProcessName, ahk_id %this_id%
  6.         if NOT this_process ;exclude emptiness
  7.                 continue
  8.         WinGetTitle, this_title, ahk_id %this_id%
  9.         if NOT this_title ;exclude start menu and empty processes
  10.                         continue
  11.         Titles%i% := this_title
  12.         FileAppend , Text, %Storage%\%this_title%.txt
  13. }


QUERING THE TEXTFILES

To query the textfiles I created 3 aliases. We issue 'IndexWindows' whenever we want up to date information. We issue 'sw <part of windowtitle>' to query window titles. IndexWindows is created just for ease of use: it simple calls the indexing script we created:

indexingalias.png
1000>>>IndexWindows>->d:\scripts\SwitchToTask\IndexWindows.exe

The 'sys-switch' alias is a system alias (the user never has to know about it) that runs a query as a parameter to the switching script we're creating later on:

sys-switch.png
1000>>>sys-switch>->D:\scripts\SwitchToTask\Switch To.exe $$1

The third and last alias is a bit more complex. (Thanks to mouser for helping me with this) It does a new search with the sys-switch alias for any textfile in the Storage directory:

switchto.png
1000>>>Switch to>->sw $$1 | dosearch +sys-switch D:\scripts\SwitchToTask\.txt $$1>+>^sw (.*)


PROCESSING RESULTS

That leaves us with the Switch To script. This script takes one parameter - the textfile launched by FARR. It then takes off the extension and switches to the window specified.

Code: Autohotkey [Select]
  1. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  3. if 0 < 1  ; need 1 parameter
  4. {
  5.     MsgBox Enter part of a window title as a parameter.
  6.     ExitApp
  7. }
  8. Loop, %0%  ; For each parameter:
  9. {
  10.                 StringLen, length, %A_Index%
  11.                 length:=length-4 ; remove .txt extensions
  12.                 StringLeft, this_title, %A_Index%, %length%
  13.                 WinActivate, i)%this_title%
  14. }


SOURCE & FINAL THOUGHTS

I was still polishing these scripts when FARRAltTab was released so at the moment it has some problems with window titles with invalid filename characters in them such as ':'. Also I'd have created some kind of FARR alias writer helper app so the person wouldn't have to know the path of the helper apps. Etcetera. However I think it is a nice proof of concept for the creative thinkers that want to use Autohotkey or any other language to harness the power of FARR.

sw.png


« Last Edit: November 29, 2007, 04:27 PM by justice »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #1 on: November 26, 2007, 07:23 AM »
Sorry the screenshots were misordered.
Download the source here:

* SwitchToTask.rar (385.49 kB - downloaded 471 times.)

tinjaw

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • View Profile
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #2 on: November 26, 2007, 07:32 AM »
Justice,

That is very cool. Thanks for sharing that with us. I am sure the knowledge will be put to good use sometime soon.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #3 on: November 26, 2007, 08:44 AM »
That is an extremely cool hack  :up:  :up:  :up:

As you say, even though the pure plugin approach off FarrAltTab will be preferable for this particular task, the tutorial you wrote could be very useful for people who may want to try other tricks -- it's a plethora of cool ideas.

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #4 on: November 26, 2007, 09:03 AM »
Thanks people :) I'm trying to think of some useful ideas for this to help others along:
  • Todo listing using textfiles with multiple helper apps (reschedule, delete, add, reminder)
  • Expand the window titles idea with a maximizer, minimize, close helper apps
  • Directory listers
The list goes on really. :)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #5 on: November 29, 2007, 12:09 PM »
This looks very interesting Justice.  :Thmbsup: I wonder if it can solve a challenge I've been thinking on how to deal with for some time. Can I somehow use your technique to let FARR at the same time do both its regular searches over file names AND search in some text files that contain lists of file and directory names?

Specifically, I have started to archive some documents related to finished projects in one large zip archive per project. It is several thousands files, most pretty small, some themselves compressed archives. Putting all such files in one big archive speeds up system wide anti-virus scans a lot. I scan the files once and then calculate a MD5 hash for the compressed archive. As long as the hash is identical I thereafter have no need for scanning it again. Now, Kaspersky anti-virus (and many other anti-virus application I suspect) spiders through regular zip archives, so to avoid that I do a password restricted archive and then place that in an extra archive. (I use no compression on the archives so unpacking twice doesn't take much time and I don't need to access the archived files very often.) Now to the problem: the downside to this archiving solution is that the files become harder to search. So far, I've tried to solve that through a disc cataloging software. But ideally I'd like to be able to use FARR or some similar tool for these searches. If I for each such archive generate a .txt that lists all its directories and files, could your technique be used to include the contents from such .txt files in general FARR searches? I could easily make a script that generates such archive file lists in some format and then copy all such file list files into a specific directory if that makes the next step easier to implement in FARR.

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #6 on: November 29, 2007, 01:02 PM »
Farr can only search filenames not inside files. However the find command prompt command can do what you want.
just create a list of textfiles like you said and then open a command prompt and type:

for %f in (*.txt) do find /i "something" %f

... to look for something inside all .txt files
« Last Edit: November 29, 2007, 01:05 PM by justice »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #7 on: November 29, 2007, 01:14 PM »
it would be very useful to have a generic plugin designed to search in simple file lists.
ie a file containing a list of other files
or a an xml file where farr is told which items should be searched for, etc.

i do have plans to write such a plugin if no one else does.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Proof of Concept: using text files to expose information to FARR
« Reply #8 on: November 29, 2007, 03:54 PM »
Ok Justice, now I read your text more closely and this time actually understood how this works (I hope)... I was fooled by the phrase "using text files to expose information to FARR ". The fact that they're textfiles isn't really important here, right? The important thing is rather that they're files. With names that FARR finds the regular way. :) So the technique wouldn't work for the scenario I sketched then, with thousands of files. But it is cool anyway. I'd like to test making a todo list handler with this when I have time (I'll put it on my todo list ;D).

The find command prompt command would work. And I could create an autohotkey frontend for that or maybe trigger it through FARR somehow. But I'd still really love to find a way to search both regular files and these file lists at the same time. So I'm hoping for the type of plugin mouser hints at here.
« Last Edit: November 29, 2007, 04:03 PM by Nod5 »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: Proof of Concept: using files to expose information to FARR
« Reply #9 on: November 29, 2007, 04:26 PM »
yeah you're right :) Fixed the title - sometimes my explanations can be overly complex :P

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: Proof of Concept: using files to expose information to FARR
« Reply #10 on: November 30, 2007, 03:46 PM »
This is a great idea, justice.. :Thmbsup: your routines for getting the window titles is just neat.. :)