FARR aliases can already start actions that make use of the active window through the special FARR variable
%LASTHWND%, which contains a window ID string. Example: use FARR to run a script with %LASTHWND% as command line parameter. The script can then condition what it does depending on what window was active. Close that window, or move it, or copy text from it, or whatever.
The new feature idea: Aliases conditional on active windowIn the alias setup we would specify conditions on the active window that must also be met for FARR to trigger the alias. Conditions could be active window processname, window class and/or window title. Exact or regex matching.
In effect FARR would for each alias test two things:
- does the string typed by the user match the alias name/regex?
- does the active window match the alias conditionals set by the user?
If yes and yes then the alias is triggered.
For example an alias named "dl" (short for download) could show different results depending on if the active window is Firefox or Chrome or some other application. Or results depending on if the active Firefox window title contains " - YouTube" (one result action: a script to download the youtube video in the active tab) or " - DonationCoder.com" (two results: scripts to save the current tab as .html or .pdf).
Two different ways the feature could be exposed to users:
1 an extra box in the alias editing window, similar to the RegEx editbox.
2 a special prefix string at the start of each Results line.
With 1 the user would make multiple aliases for "dl".
With 2 the user would make one "dl" alias but then add more lines in the results box with the special prefix.
Mockup code for case 2:
#If(win_process = "Firefox.exe" and win_title = regex("^ - YouTube$") Save youtube video | C:\folder\script.ahk %LASTHWND%
Or alternatively put the conditional on a separate line and apply it to all results line below it until a new conditional line is encountered. Mockup:
#If win_process = "Firefox.exe" and win_title = regex("^ - YouTube$")
We can think of this feature a bit like how the context menu in Windows File Explorer shows different actions depending on what extension the selected file has. Or the #IfWinActive syntax for context-sensitive hotkeys in AutoHotkey.
Some more use cases: The alias "cs" could be used to immediately (using the special FARR string "dolaunch") run a cheat sheet file for the active application/process. Alias "help" could show help resources relevant to the active application.