Open URLs in different browsers Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Open URLs in different browsers

13 May 2021, 16:01

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)?
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Open URLs in different browsers

13 May 2021, 16:58

You can use A_ComputerName and also an array or subarray that maps the menu name to the browser.
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Open URLs in different browsers

13 May 2021, 17:50

Code: Select all

BrowserArray := {PC1: "chrome.exe --options ", PC2: "firefox.exe -options "}
Like this?
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Open URLs in different browsers

13 May 2021, 17:58

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
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Open URLs in different browsers

14 May 2021, 15:50

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).
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Open URLs in different browsers

14 May 2021, 16:34

Can you post your revision?
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Open URLs in different browsers  Topic is solved

14 May 2021, 16:43

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.
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Open URLs in different browsers

14 May 2021, 16:52

And your text file?
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Open URLs in different browsers

14 May 2021, 16:56

Code: Select all

Format of links.txt
;Arrays;https://autohotkey.com/docs/Arrays
Ecimeric
Posts: 130
Joined: 11 Jan 2017, 02:23

Re: Open URLs in different browsers

14 May 2021, 19:52

I had missed global for PC1.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], ishida20, jameswrightesq, Lem2001 and 411 guests