Opening Brave and keeping it open via Autohotkey


#1

Opening Brave can be tricky. This Autohotkey script may be useful.

; This Autohotkey script opens the Brave browser.
; By Michael Weiner
; 11 March 2018
; -------------------------------------------------
; Setup:
; 1. Create a pinned tab in Brave.
; 2. Set Brave preferences to open to a new tab.
; Brave will exit when you close the last open tab!
; Creating a pinned tab can help to remind you when you are on the last tab
; and should avoid closing it, so that the browser does not exit.
; Here is an example of a tab that you can pin: http://cogit.net/lastpage.shtml
; When Brave starts, it will sometimes open to the first, pinned tab,
; and will sometimes open to the second, blank tab. This seems random.
; -------------------------------------------------
; Find the Brave browser.
EnvGet, lad, LOCALAPPDATA
process = Brave.exe
app := lad . "\Brave\" . process
; We need to specify Brave's window title by its process,
; because Brave uses tabs' names as window titles.
brave := "ahk_exe " . process
; -------------------------------------------------
; Determine whether Brave is already running.
Process, exist, %process%
newPID = %ErrorLevel%
If newPID > 0
{
 ; Brave is already running.
 WinActivate, %brave%
}
else
{
 ; Brave is not already running.
 ; The numbers in the splash command indicate width and height of the splash window.
 ; This is followed by the splash window's title and text.
 SplashTextOn, 300, 50, Brave, Please wait....
 Run, %app%
 WinWaitActive, %brave%
 SplashTextOff
 ; We need a bit more time for the browser window to be ready.
 Sleep, 2000
 ; Using ControlSend in Brave is difficult due to varying control names,
 ; so we'll instead just activate the browser window and then send text to it.
 WinActivate, %brave%
 ; Activate the second tab, which is a new, blank tab.
 Send ^2
 ; In case the second tab's URL is listed incorrectly from the first tab,
 ; focus on the address bar, and delete its URL.
 Send ^l{BACKSPACE}
}

#2

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.