topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Friday March 29, 2024, 6:44 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: New feature idea: Aliases conditional on active window  (Read 10133 times)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
New feature idea: Aliases conditional on active window
« on: November 18, 2019, 06:58 AM »
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 window
In 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.

nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: New feature idea: Aliases conditional on active window
« Reply #1 on: November 20, 2019, 01:46 PM »
Excellent idea !  :up:

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: New feature idea: Aliases conditional on active window
« Reply #2 on: December 08, 2019, 03:03 AM »
I can definitely see the value of having farr results be conditioned on the current/last active window..

But I am wary of trying to add stuff to the alias configuration dialog to support this.. it feels like an awkward match.

What you want COULD be done using a FARR plugin.. the only trouble is the complexity involved in writing a FARR plugin.. 

It seems to me a cleaner approach might be an easier and more flexible system for writing short script-like plugins..  That would let you more easily write a mini script to do what you want.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: New feature idea: Aliases conditional on active window
« Reply #3 on: December 13, 2019, 06:26 AM »
I am wary of trying to add stuff to the alias configuration dialog to support this.. it feels like an awkward match.
How so? The feature would condition when an alias is triggered and what results it triggers. Seems like alias configuration to me.

It seems to me a cleaner approach might be an easier and more flexible system for writing short script-like plugins..  That would let you more easily write a mini script to do what you want.
Not sure if I follow this. How would we go about that in these 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. Would I write one script-like plugin per such active window context dependent alias string that I want. That is, one for "cs", one for "help" and so on?


More thoughts on this kind of feature
Two use cases where different implementations would be the best fit, I now reckon.

Case1 We want to make a single alias string, or single regex pattern, to trigger different results depending on the active window (or other conditions...) and we might have many such windows. Example: "help" shows help resources relevant to the active application.
Here ability to add #If declaratives on lines in the results list in the alias configuration would be handy and easy to overview. Mockup:
#If win_process = "Firefox.exe"
dolaunch a.exe
#If win_process = "Chrome.exe"
dolaunch b.exe
and so on for 10 other windows.

(For my own use I currently achieve this effect through an alias that runs an AutoHotkey script with %LASTHWND% as parameter, and then the script looks up that window and takes conditional action. But my thinking is that FARR users might be interested in the basics of that without having to resort to external scripts. A minor difference is that with this external script approach we can't make FARR not trigger a regex alias if none of the target windows are active. That is we can't make FARR do a regular search for files with "help" if the active window is not one of those we have special actions for in the script.)

Case2 We want to make a lot of different alias strings to trigger only if some window is active (or other conditions...)
For example we want aliases for the strings "help", "cs", "close" and so on that only trigger if the active window is InkScape.

Here it would make more sense to be able add the condition to a set of lines in the list of aliases in an alias file in FARR Options. (Under the hood: the condition would exist as a parent tag with a number of <AliasEntry> items as children in the FARR myaliases.alias XML file)

Or, perhaps more feasible, one condition per alias file. So in the example we'd make inkscape.alias and have all aliases in it trigger only if the active window condition is met. Users could be exposed to that through an edit field or a button to show an editfield in the section above the list of aliases in FARR options.
1.pngNew feature idea: Aliases conditional on active window

Under the hood: store condition in a tag in inkscape.alias XML file. Mockup:
<FarrAliasFile>
    <FileFormatVersion>1</FileFormatVersion>
    <AliasSetCondition>win_process = InkScape.exe</AliasSetCondition>
    <AliasSetDescription>Custom User Alias File</AliasSetDescription>

Edit: Or, to change as little as possible in the current FARR options UI, let users add alias condition strings to the alias file description box (AliasSetDescription XML tag)! FARR would detect if the string in that box starts with a declarative like "#if" and then treat the rest of the string as conditions.
« Last Edit: December 13, 2019, 06:54 AM by Nod5 »

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: New feature idea: Aliases conditional on active window
« Reply #4 on: December 30, 2019, 12:16 PM »
Here ability to add #If declaratives on lines in the results list in the alias configuration would be handy and easy to overview. Mockup:
#If win_process = "Firefox.exe"
dolaunch a.exe

Ok so that would not be very hard to add and wouldn't require modifying the user interface, so that was my main concern.

Now the question is simply how complicated these #IF rules have to be..  The use of and/or type expressions are the kind of thing that would be easy if there was a proper scripting langauge support embedded in farr, but there isn't..

If it was just one very simple #IF directive, without support for and/or expressions, like
#IF_REGEXMATCH %winprocess% "notepad"

Then it would be pretty trivial to add..