V1 change default browser

Post your working scripts, libraries and tools for AHK v1.1 and older
MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

V1 change default browser

29 Oct 2023, 08:28

Interestingly enough this will ask you for the default browser, LMK if anyone knows of an easier way to do it .

Code: Select all

^+#W::
    Send, ^c

	Gui, Destroy

    Gui, Add, Text, x10 y290, Select a Browser: ; Specific position
    Gui, Add, Button, x10 y310 w150 h30, Firefox ; Specific position
    Gui, Add, Button, x170 y310 w150 h30, Brave ; Specific position

	Gui, Add, Text, x10 y350, Search text: ; title
    Gui, Add, Edit, x10 y370 w300 h30 vUserInput ; textbox
    Gui, Show
Return



; Set the default browser using Windows AssocQueryString 
SetDefaultBrowser(browserName) {
    RegRead, browserPath, HKLM, SOFTWARE\Classes\http\shell\open\command
    RegWrite, REG_SZ, HKCU, Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice, ProgId, %browserName%
    RegWrite, REG_SZ, HKCU, Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice, ProgId, %browserName%
    
    DisplayTrayTip("Default browser set to " . browserName)
    WinClose Settings
}

DisplayTrayTip(text) {
    TrayTip, Notification, %text%, 2
}

ButtonFirefox:
    SetDefaultBrowser("Firefox")
	TrayTip, Notification, %SetDefaultBrowser%, 2
    Gui, Destroy
Return

ButtonBrave:
    SetDefaultBrowser("Brave")
		TrayTip, Notification, %SetDefaultBrowser%, 2
    Gui, Destroy
Return


MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: V1 change default browser

29 Oct 2023, 09:33

And I added it as a part of my GUI for searching copied or highlighted text
So basically you get this pop-up after you click a button to search if you click the change default browser button first
image.png
image.png (77.38 KiB) Viewed 473 times

Code: Select all




#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%

; Hotkey to activate the search engine selection GUI (Win+Ctrl+Shift+W)
^+#W::
    Send, ^c

	Gui, Destroy
    Sleep, 200 ; Wait for clipboard to capture the selected text
    Gui, Add, Text, , Select a Search Engine:
    Gui, Add, Button, x10 y30 w150 h30, Google
    Gui, Add, Button, x170 y30 w150 h30, DuckDuckGo
    Gui, Add, Button, x10 y70 w150 h30, Yandex
    Gui, Add, Button, x170 y70 w150 h30, Bing
    Gui, Add, Button, x10 y110 w150 h30, Yahoo
    Gui, Add, Button, x170 y110 w150 h30, Swisscows

    Gui, Add, Text, x10 y150, Select database:
    Gui, Add, Button, x10 y170 w150 h30, UpToDate
    Gui, Add, Button, x170 y170 w150 h30, DynaMed
    Gui, Add, Button, x10 y210 w150 h30, Amboss
    Gui, Add, Button, x170 y210 w150 h30, ClinicalKey
    Gui, Add, Button, x10 y250 w150 h30, PubMed
    Gui, Add, Button, x170 y250 w150 h30, ScienceDirect

    Gui, Add, Button, x10 y310 w300 h30, ChangeDefaultBrowser 
	
	
	Gui, Add, Text, x10 y350, Search text: ; title
    Gui, Add, Edit, x10 y370 w300 h30 vUserInput ; textbox
    Gui, Show
Return





; Buttons to select the search engine

ButtonYahoo:
    searchOrVisitFromClip("https://search.yahoo.com/search;_ylt=AwrNag_OGT5ljbgnQQdDDWVH;_ylc=X1MDMTE5NzgwNDg2NwRfcgMyBGZyAwRmcjIDcDpzLHY6c2ZwLG06c2ItdG9wBGdwcmlkA1V4T2ZWazdKUTJTZVkwZmYzZ0dYQUEEbl9yc2x0AzAEbl9zdWdnAzEwBG9yaWdpbgNzZWFyY2gueWFob28uY29tBHBvcwMwBHBxc3RyAwRwcXN0cmwDMARxc3RybAM0BHF1ZXJ5A3Rlc3QEdF9zdG1wAzE2OTg1Njg2NTY-?p=")
    Gui, Destroy
Return

ButtonGoogle:
    searchOrVisitFromClip("https://www.google.com/search?q=")
    Gui, Destroy
Return

ButtonDuckDuckGo:
    searchOrVisitFromClip("https://duckduckgo.com/?q=")
    Gui, Destroy
Return

ButtonYandex:
    searchOrVisitFromClip("https://www.yandex.com/search/?text=")
    Gui, Destroy
Return

ButtonBing:
    searchOrVisitFromClip("https://www.bing.com/search?q=")
    Gui, Destroy
Return

ButtonUpToDate:
    searchOrVisitFromClip("https://www-uptodate-com/contents/search?search=")
    Gui, Destroy
Return

ButtonDynaMed:
    searchOrVisitFromClip("https://www-dynamed-com/results?q=")
    Gui, Destroy
Return

ButtonAmboss:
    searchOrVisitFromClip("https://next.amboss.com/us/search?q=")
    Gui,Destroy
Return

ButtonSwisscows:
    searchOrVisitFromClip("https://swisscows.com/en/web?query=")
    Gui,Destroy
Return

ButtonClinicalKey:
    searchOrVisitFromClip("https://www-clinicalkey-com/#!/search/")
    Gui, Destroy
Return

ButtonScienceDirect:
    searchOrVisitFromClip("https://www-sciencedirect-com/search?pub=")
    Gui, Destroy
Return

ButtonPubMed:
	searchOrVisitFromClip("https://pubmed.ncbi.nlm.nih.gov/?term=")
    Gui, Destroy
Return


searchOrVisitFromClip(searchUrl) {
    GuiControlGet, UserInput, , UserInput ; Get the value from the UserInput GUI control

	;check if textbox contains text
	if (UserInput != "") {
	Clipboard := UserInput
    run, % searchUrl clipboard
	}
	
	;check if textbox is empty 
	 if (UserInput = "") {
	
    if (clipboard ~= "^https?://") {
        run, % clipboard
    } else {
        run, % searchUrl clipboard
    }
	}
}


;reference https://stackoverflow.com/questions/32354861/how-to-find-the-default-browser-via-the-registry-on-windows-10

; Set the default browser using the Windows AssocQueryString method
SetDefaultBrowser(browserName) {
    RegRead, browserPath, HKLM, SOFTWARE\Classes\http\shell\open\command
    RegWrite, REG_SZ, HKCU, Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice, ProgId, %browserName%
   
    WinClose Settings
}


ButtonChangeDefaultBrowser:
    SetDefaultBrowser("Brave")
    TrayTip, Notification, Default browser pop-up will appear at search, 10
Return


MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: V1 change default browser

14 Mar 2024, 08:06

This is sad, with Windows 10 updated, it seems this does not work anymore.... It was a great way to change the default browser quickly. Now I am not able to provoke the opening of the "how do you want to open this" window anymore :(
MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: V1 change default browser

15 Mar 2024, 03:26

Alright this will have to do... but this just opens the default section in the Windows settings at there you can not use keyboard shortcuts to choose the browser it seems

edit: no you can use tab/shift+tab and Enter to navigate and then Alt+F4 to close the settings window.

viewtopic.php?f=6&t=122359&p=563220#p563220

Code: Select all



;reference https://stackoverflow.com/questions/32354861/how-to-find-the-default-browser-via-the-registry-on-windows-10
;reference https://www.autohotkey.com/boards/viewtopic.php?t=5015




ButtonChangeDefaultBrowser:

	Run ms-settings:defaultapps
Sleep 1500
Send {Tab 5}{Enter} ;Highlight Default Browser + Select
Sleep 1000
Send {Tab 2} ;Highlight Chrome + Select


    TrayTip, Notification, Choose default browser in settings, 10
Return


image.png
image.png (288.52 KiB) Viewed 149 times

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Bing [Bot], GollyJer and 55 guests