Page 1 of 1

Open URLs in different browsers

Posted: 13 May 2021, 16:01
by Ecimeric

Code: Select all

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
}
How can I use a different browser in Launch depending on whether I am using PC1 or PC2, and depending on the browsers that I specify for different menus (which is why I have not simply specified them in Launch)?

Re: Open URLs in different browsers

Posted: 13 May 2021, 16:58
by mikeyww
You can use A_ComputerName and also an array or subarray that maps the menu name to the browser.

Re: Open URLs in different browsers

Posted: 13 May 2021, 17:50
by Ecimeric

Code: Select all

BrowserArray := {PC1: "chrome.exe --options ", PC2: "firefox.exe -options "}
Like this?

Re: Open URLs in different browsers

Posted: 13 May 2021, 17:58
by mikeyww
Yes, but you need not take my word for it. Give it a go! :)

An array is not required, as you have shown through use of a conditional statement instead.

I saw a handy guide recently: "If a script achieves your goal, it is a solution." --lexikos

Re: Open URLs in different browsers

Posted: 14 May 2021, 15:50
by Ecimeric
I got the script working by removing the %s from %BrowserPC1% : %BrowserPC2%; however, I cannot figure out why BrowserPC2 is launched when I am on PC1 (which is defined separately).

Re: Open URLs in different browsers

Posted: 14 May 2021, 16:34
by mikeyww
Can you post your revision?

Re: Open URLs in different browsers  Topic is solved

Posted: 14 May 2021, 16:43
by Ecimeric

Code: Select all

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
}
AFAICS, this should launch Chrome on PC1, since its order corresponds with BrowserPC1.

Re: Open URLs in different browsers

Posted: 14 May 2021, 16:52
by mikeyww
And your text file?

Re: Open URLs in different browsers

Posted: 14 May 2021, 16:56
by Ecimeric

Code: Select all

Format of links.txt
;Arrays;https://autohotkey.com/docs/Arrays

Re: Open URLs in different browsers

Posted: 14 May 2021, 19:52
by Ecimeric
I had missed global for PC1.