DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
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)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.

; setting variables
Storage = %A_ScriptDir%
FileDelete , %Storage%\*.txt
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)
WinGet, id, list,,, Program Manager ; get list of all foreground ids
Loop, %id%
{
	this_id := id%A_Index%
	WinGet, this_process, ProcessName, ahk_id %this_id%
	if NOT this_process ;exclude emptiness
		continue
	WinGetTitle, this_title, ahk_id %this_id%
	if NOT this_title ;exclude start menu and empty processes
			continue
	Titles%i% := this_title
	FileAppend , Text, %Storage%\%this_title%.txt
}


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
Code
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
Code
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
Code
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)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode RegEx
if 0 < 1  ; need 1 parameter
{
    MsgBox Enter part of a window title as a parameter.
    ExitApp
}
Loop, %0%  ; For each parameter:
{
		StringLen, length, %A_Index%
		length:=length-4 ; remove .txt extensions
		StringLeft, this_title, %A_Index%, %length%
		WinActivate, i)%this_title%
}


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, 10:27 PM by justice »

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Proof of Concept: using text files to expose information to FARR
« Reply #1 on: November 26, 2007, 01:23 PM »
Sorry the screenshots were misordered.
Download the source here:

SwitchToTask.rar (385.5 KB)

tinjaw

  • I'm so glad breakbeat techno isn't an illegal drug
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • Participated in NANY Challenge Twice
    • Coding Snacks
    • Military Service Badge - US Army
    • Linux User
Re: Proof of Concept: using text files to expose information to FARR
« Reply #2 on: November 26, 2007, 01:32 PM »
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,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Proof of Concept: using text files to expose information to FARR
« Reply #3 on: November 26, 2007, 02:44 PM »
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

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Proof of Concept: using text files to expose information to FARR
« Reply #4 on: November 26, 2007, 03:03 PM »
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,175
    • Coding Snacks
    • Participated in NANY Challenge Three Times
    • Plugin Coding Medal
Re: Proof of Concept: using text files to expose information to FARR
« Reply #5 on: November 29, 2007, 06: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

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Proof of Concept: using text files to expose information to FARR
« Reply #6 on: November 29, 2007, 07: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, 07:05 PM by justice »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Proof of Concept: using text files to expose information to FARR
« Reply #7 on: November 29, 2007, 07: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,175
    • Coding Snacks
    • Participated in NANY Challenge Three Times
    • Plugin Coding Medal
Re: Proof of Concept: using text files to expose information to FARR
« Reply #8 on: November 29, 2007, 09: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, 10:03 PM by Nod5 »

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Proof of Concept: using files to expose information to FARR
« Reply #9 on: November 29, 2007, 10: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
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: Proof of Concept: using files to expose information to FARR
« Reply #10 on: November 30, 2007, 09:46 PM »
This is a great idea, justice.. :Thmbsup: your routines for getting the window titles is just neat.. :)

Original address: https://www.donationcoder.com/forum/index.php?topic=11021.0