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 TECHNIQUEAs 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 TITLESWe 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%
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:
WinGet, id
, list
,,, Program Manager
; get list of all foreground ids {
this_id := id%A_Index%
WinGet, this_process
, ProcessName
, ahk_id
%this_id% if NOT this_process ;exclude emptiness
if NOT this_title ;exclude start menu and empty processes
Titles%i% := this_title
}
QUERING THE TEXTFILESTo 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:
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:
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 RESULTSThat 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.
#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
{
MsgBox Enter part of a window title as a parameter
. }
Loop, %0%
; For each parameter: {
length:=length-4 ; remove .txt extensions
}
SOURCE & FINAL THOUGHTSI 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.