topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Sunday November 10, 2024, 3:06 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: displaying expanded user variables in aliases  (Read 5392 times)

jinxx

  • Supporting Member
  • Joined in 2014
  • **
  • default avatar
  • Posts: 10
    • View Profile
    • Donate to Member
displaying expanded user variables in aliases
« on: March 14, 2021, 10:55 PM »
So I have many aliases with user variables sandwiched in
and sometimes I want to take those aliases for use elsewhere with the user variables expanded,
the string "%uservar.folder.stuff%" isn't any use to me outside of FARR, so I'm wondering if there's some way to take an alias and expand all its FARR user variables

naturally I could go into my uservariables and copy paste etc... but this becomes cumbersome when i have aliases with 3+ user variables in them
of course I could convert my use-case to utilizing windows environment variables, which in the long term I may do

if it's not a feature then I guess consider this a feature request for the "edit group alias" window

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: displaying expanded user variables in aliases
« Reply #1 on: March 15, 2021, 11:14 AM »
I don't think FARR has that feature built in, but it would be a useful feature. I have AutoHotkey code that resolves the FARR user variables. I'l clean that up and post here as a helper tool for FARR when I have more time.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: displaying expanded user variables in aliases
« Reply #2 on: March 16, 2021, 09:25 AM »
Save to FARR_resolve_alias_variables.ahk (with UTF-8 BOM encoding). Requires AutoHotkey

Will work in most cases, but might fail on complex alias text with e.g. escaped % characters.

Code: Autohotkey [Select]
  1. SetWorkingDir %A_ScriptDir%
  2.  
  3. ; FARR_resolve_alias_variables.ahk
  4.  
  5. ; by Nod5 on 2021-03-16
  6.  
  7. ; A helper tool for FARR (Find And Run Robot) written in AutoHotkey
  8.  
  9. ; Reads alias result from active FARR "Edit Group Alias" window
  10. ; and resolves (converts) FARR's UserVar variables to text values
  11.  
  12. ; For example the variable "%uservar.Browser.Chrome%" is replaced
  13. ; with e.g. "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
  14.  
  15. ; How to use:
  16. ; Run script and press F8 when FARR Options "Edit Group Alias" window is active
  17. ; A MsgBox shows the results lines with resolved UserVars
  18.  
  19. ; Optional: uncomment lines near end of script to also
  20. ; - Copy text to clipboard
  21. ; - Write text to .txt file
  22.  
  23. ; Discussion
  24. ;   https://www.donationcoder.com/forum/index.php?topic=51199.0
  25.  
  26.  
  27. ; default path to FARR .ini file (edit this filepath if the .ini is in another location)
  28. vFarrIni := "C:\Users\" A_UserName "\Documents\DonationCoder\FindAndRunRobot\FindAndRunRobot.ini"
  29. return
  30.  
  31. #IfWinActive, Edit Group Alias ahk_exe FindAndRunRobot.exe ahk_class TAliasForm
  32. F8::
  33.   if !FileExist(vFarrIni)
  34.   {
  35.     MsgBox % "Error: FindAndRunRobot.ini not found.`n`nEdit script and add correct path to it."
  36.     ExitApp
  37.   }
  38.   ; get text from results editbox
  39.   ControlGetText, vText, TMemo2, A
  40.  
  41.   ; read UserVar data from FARR .ini
  42.   IniRead, vUserVars, % vFarrIni, ExtraSettings, UserVars, %A_Space%
  43.  
  44.   ; split lines to array
  45.   aUserVars := StrSplit(vUserVars, ">n>")
  46.  
  47.   ; object to store full variable/value pairs
  48.   aMap := Object()
  49.  
  50.   For Key, vLine in aUserVars
  51.   {
  52.     vLine := TRim(vLine)
  53.    
  54.     ; skip blank or comment line
  55.     if !vLine or (SubStr(vLine, 1, 2) = "//")
  56.       continue
  57.  
  58.     ; [Section]
  59.     if RegExMatch(vLine, "^\[(.+)\]$", vMatch)
  60.       vSection := vMatch1
  61.  
  62.     ; if variable line then get variable/value pair and add to map array
  63.     ; prefix variable name "uservar." and last found section name (if any)
  64.     if RegExMatch(vLine, "U)^(.+)=(.+)$", vMatch)
  65.     {
  66.       vVarName := "uservar." ( vSection ? vSection "." : "") vMatch1
  67.       vValue    := vMatch2
  68.       aMap["" vVarName] := vValue
  69.     }
  70.   }
  71.  
  72.   ; resolve
  73.   For vVarName, vValue in aMap
  74.     vText := StrReplace(vText, "%" vVarName "%", vValue) ; replace all
  75.  
  76.   ; show resolved text
  77.   MsgBox % vText
  78.  
  79.   ; put on clipboard
  80.   ;Clipboard := vText
  81.  
  82.   ; write to .txt file in this script's folder
  83.   ;FileAppend, % vText, % A_ScriptDir "\alias_resolved_" A_Now ".txt", UTF-8-RAW
  84. return
  85.  
  86.  
  87. ; ----------------------------
  88. ; notes of FARR User Variables (UserVar)
  89. ; ----------------------------
  90. ;   Used as variables in aliases
  91. ;   Set in FARR > Options > Lists > User Variables
  92. ;   Stored in FindAndRunRobot.ini
  93. ;     Default path C:\Users\<username>\Documents\DonationCoder\FindAndRunRobot\FindAndRunRobot.ini
  94.  
  95. ; Format in Options "User Variables" pane:
  96. ; -----
  97. ; TopTest=C:\folder\test.exe
  98. ; [SectionName]
  99. ; VarName=Value
  100. ; VarName2=Value2
  101. ; // comment line
  102. ;
  103. ; [Browser]
  104. ; Chrome=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
  105. ; Firefox=C:\b\firefox.exe
  106. ; -----
  107. ; Note: it is allowed to create variables above the first [Section]
  108. ; Note: comments must be on separate lines. Not allowed: VarName=Value //comment
  109.  
  110. ; -----
  111. ; Format in FARR aliases:
  112. ; -----
  113. ;   %uservar.TopTest%
  114. ;   %uservar.SectionName.VarName%
  115. ;   %uservar.Browser.Chrome%
  116. ; -----
  117.  
  118. ; -----
  119. ; Format in FindAndRunRobot.ini
  120. ; -----
  121. ; Stored as a single line, ">n>" is linebreak separator
  122. ; Example:
  123. ; UserVars=TopTest=C:\folder\test.exe>n>[SectionName]>n>VarName=Value>n>VarName2=Value2>n>// comment line>n>>n>[Browser]>n>Chrome=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe>n>Firefox=C:\b\firefox.exe
  124. ; ----------------------------