56
Find And Run Robot / Re: displaying expanded user variables in aliases
« 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.
Will work in most cases, but might fail on complex alias text with e.g. escaped % characters.
Code: Autohotkey [Select]
- SetWorkingDir %A_ScriptDir%
- #SingleInstance force
- ListLines, Off
- ; FARR_resolve_alias_variables.ahk
- ; by Nod5 on 2021-03-16
- ; A helper tool for FARR (Find And Run Robot) written in AutoHotkey
- ; Reads alias result from active FARR "Edit Group Alias" window
- ; and resolves (converts) FARR's UserVar variables to text values
- ; For example the variable "%uservar.Browser.Chrome%" is replaced
- ; with e.g. "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
- ; How to use:
- ; Run script and press F8 when FARR Options "Edit Group Alias" window is active
- ; A MsgBox shows the results lines with resolved UserVars
- ; Optional: uncomment lines near end of script to also
- ; - Copy text to clipboard
- ; - Write text to .txt file
- ; Discussion
- ; https://www.donationcoder.com/forum/index.php?topic=51199.0
- ; default path to FARR .ini file (edit this filepath if the .ini is in another location)
- return
- F8::
- {
- MsgBox % "Error: FindAndRunRobot.ini not found.`n`nEdit script and add correct path to it."
- }
- ; get text from results editbox
- ; read UserVar data from FARR .ini
- ; split lines to array
- aUserVars := StrSplit(vUserVars, ">n>")
- ; object to store full variable/value pairs
- aMap := Object()
- For Key, vLine in aUserVars
- {
- vLine := TRim(vLine)
- ; skip blank or comment line
- ; [Section]
- vSection := vMatch1
- ; if variable line then get variable/value pair and add to map array
- ; prefix variable name "uservar." and last found section name (if any)
- {
- vVarName := "uservar." ( vSection ? vSection "." : "") vMatch1
- vValue := vMatch2
- aMap["" vVarName] := vValue
- }
- }
- ; resolve
- For vVarName, vValue in aMap
- vText := StrReplace(vText, "%" vVarName "%", vValue) ; replace all
- ; show resolved text
- MsgBox % vText
- ; put on clipboard
- ;Clipboard := vText
- ; write to .txt file in this script's folder
- ;FileAppend, % vText, % A_ScriptDir "\alias_resolved_" A_Now ".txt", UTF-8-RAW
- return
- ; ----------------------------
- ; notes of FARR User Variables (UserVar)
- ; ----------------------------
- ; Used as variables in aliases
- ; Set in FARR > Options > Lists > User Variables
- ; Stored in FindAndRunRobot.ini
- ; Default path C:\Users\<username>\Documents\DonationCoder\FindAndRunRobot\FindAndRunRobot.ini
- ; Format in Options "User Variables" pane:
- ; -----
- ; TopTest=C:\folder\test.exe
- ; [SectionName]
- ; VarName=Value
- ; VarName2=Value2
- ; // comment line
- ;
- ; [Browser]
- ; Chrome=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
- ; Firefox=C:\b\firefox.exe
- ; -----
- ; Note: it is allowed to create variables above the first [Section]
- ; Note: comments must be on separate lines. Not allowed: VarName=Value //comment
- ; -----
- ; Format in FARR aliases:
- ; -----
- ; %uservar.TopTest%
- ; %uservar.SectionName.VarName%
- ; %uservar.Browser.Chrome%
- ; -----
- ; -----
- ; Format in FindAndRunRobot.ini
- ; -----
- ; Stored as a single line, ">n>" is linebreak separator
- ; Example:
- ; 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
- ; ----------------------------