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. 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.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; setting variables
Storage = %A_ScriptDir%
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:
QUERING THE TEXTFILES WinGet,
Program Manager ; get list of all foreground ids
this_id := id%A_Index%
if NOT this_process ;exclude emptiness
if NOT this_title ;exclude start menu and empty processes
Titles%i% := this_title
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:
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:
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:
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.
SOURCE & FINAL THOUGHTS #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
if 0 < 1 ; need 1 parameter
part of a window title as a parameter.
%0% ; For each parameter:
length:=length-4 ; remove .txt extensions
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.