topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Sunday October 6, 2024, 3:22 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: example/howto: alias appcapresults command with AutoHotkey  (Read 4274 times)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
example/howto: alias appcapresults command with AutoHotkey
« on: October 12, 2020, 03:54 AM »
In FindAndRunRobot version 2.234.01 mouser added a useful alias command called appcapresults

appcapresults runs an external program, waits for it to output to stdout and then display that output (if correctly formatted) as FARR results lines.

This post shows examples on how to use it together with AutoHotkey to generate a results list in FARR.

Code: Autohotkey [Select]
  1. SetWorkingDir %A_ScriptDir%
  2.  
  3. ; example AutoHotkey script for use with FARR appcapresults
  4.  
  5. ; prepare a results list
  6. ; each line adheres to FARR's format for lines in alias results
  7. ; note: must have a blank line at the end, otherwise the last text line won't show in FARR
  8. Results =
  9. (
  10. Notepad | C:\Windows\System32\notepad.exe
  11. Paint | C:\Windows\System32\mspaint.exe
  12.  
  13. )
  14. ; use fileappend with * to write the list to stdout
  15. FileAppend, % Results , *

1. Save the above script as C:\folder\example.ahk and compile to C:\folder\example.exe

2. Next create a FARR alias
alias name: appcapresults example
alias regex: ^appcap$
alias results:
example | appcapresults C:\folder\example.exe

After that you can type "appcap" in FARR and press enter to get something like this

appcap.png

To make the alias trigger automatically, without Enter, you can change the alias to
example | dolaunch appcapresults C:\folder\example.exe

That's the basics. But this opens up the possibility of complex, conditional aliases. Some possibilities:
- Have the script present different results lists based on the current day/time
- Pass the %lasthwnd% parameter from FARR to the script and have script present different results depending on what window was active before FARR. For example we could make the alias "help" and have it show our own customized help hints based on what application is active. Related earlier post.
- Another example is to have the script search Everything via its SDK and display the search results in FARR, in effect creating an alternative Everything plugin for FARR. This works, though I don't have the code cleaned up enough to post it yet.


edit:

More complex example: alias results conditional on the active window

Code: Autohotkey [Select]
  1. SetWorkingDir %A_ScriptDir%
  2.  
  3. ; complex example conditional AutoHotkey script for use with FARR appcapresults
  4.  
  5. ; window id for active window as parameter sent from FARR
  6. LastHwnd := A_Args[1]
  7.  
  8. ; if active window is Firefox
  9. If LastHwnd and WinExist("ahk_exe Firefox.exe ahk_id " LastHwnd)
  10. {
  11.   Results =
  12.   (LTrim
  13.   Google | https://www.google.com/
  14.   Wiki | https://en.wikipedia.org/
  15.  
  16.   )
  17. }
  18.  
  19. ; if active window is MS Paint
  20. If LastHwnd and WinExist("ahk_exe mspaint.exe ahk_id " LastHwnd)
  21. {
  22.   Results =
  23.   (LTrim
  24.   // use FARR sendkeys command to send action shortcuts to MS Paint
  25.   Resize | sendkeys ^w
  26.   Crop selection | sendkeys ^(+x)
  27.  
  28.   )
  29.  
  30. }
  31.  
  32. ; use fileappend with * to write the list to stdout
  33. FileAppend, % Results , *

1. Save the above script as C:\folder\example2.ahk and compile to C:\folder\example2.exe

2. Next create/edit a FARR alias
alias name: appcapresults example2
alias regex: ^appcap$
alias results:
example | appcapresults C:\folder\example2.exe %lasthwnd%

Type "appcap" and press enter over MS Paint and Firefox to get different results

mspaint2.pngexample/howto: alias appcapresults command with AutoHotkey

firefox.pngexample/howto: alias appcapresults command with AutoHotkey

GIF of sending the action shortcuts to MS Paint from FARR
https://i.imgur.com/0SE2wDQ.mp4

edit2: improved complex example
« Last Edit: October 13, 2020, 06:55 AM by Nod5 »

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • View Profile
    • Donate to Member
Re: example/howto: alias appcapresults command with AutoHotkey
« Reply #1 on: October 12, 2020, 07:51 AM »
Ingenious, thanks!

wjamoe

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 99
    • View Profile
    • Donate to Member
Re: example/howto: alias appcapresults command with AutoHotkey
« Reply #2 on: October 16, 2020, 10:59 AM »
very nice, thanks!