Reputation: 381
global AssocArray := {}
Array := []
Loop, Read, links.txt
Array.Push(StrSplit(A_LoopReadLine, ";"))
for index, element in Array {
Browser := Func("Launch").Bind("chrome.exe --options ", "firefox.exe -options ")
Menu, MyMenu, Add, % element.2, % Browser
AssocArray[element.2] := element.3
}
Menu, MyMenu, Show
Launch(BrowserPC1, BrowserPC2, ItemName, ItemPos) {
Browser := A_ComputerName = PC1 ? %BrowserPC1% : %BrowserPC2%
Run, % Browser AssocArray[ItemName]
return
}
Format of links.txt:
;Arrays;https://autohotkey.com/docs/Arrays
How can I use a different browser in Launch
depending on whether I am using PC1
or PC2
, and which browsers I specify for different menus (which is why I have not simply specified them in Launch
)? I am getting an illegal character error because of (I assume) the dashes.
Upvotes: 2
Views: 195
Reputation: 6489
The mistake is here:
Browser := A_ComputerName = PC1 ? %BrowserPC1% : %BrowserPC2%
You're trying to use dynamic variables.
When in an expression statement, you don't refer to variables via the legacy AHK way of wrapping them in %
s. You just simply type their name, like so:
Browser := A_ComputerName = PC1 ? BrowserPC1 : BrowserPC2
Another thing. Where is the variable PC1
supposed to be defined?
Did you maybe mean to use it as a literal string ("PC1"
)?
Upvotes: 1