How to start a program and hide it immediately?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Super Foxy
Posts: 16
Joined: 22 Feb 2023, 11:28

How to start a program and hide it immediately?

18 Apr 2024, 15:26

I want a specific chrome window to start with windows start, and I already know hot to do that, but I also want the window to start already hidden, without autohotkey having to wait for the title to load, so is there a way to start a chrome window (or any other program) with some kind of attribute to make it hidden?
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: How to start a program and hide it immediately?

18 Apr 2024, 16:33

If I'm reading the help docs correctly, this should work:

Code: Select all

#Requires AutoHotkey v2+
;Note space before webpage.
target := "C:\Program Files\Google\Chrome\Application\chrome.exe" " https://www.autohotkey.com/docs/v2/lib/Run.htm"
Run target,, "Min"
It doesn't seem to be starting minimized though....
ste(phen|ve) kunkel
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: How to start a program and hide it immediately?

18 Apr 2024, 16:49

FYI, this:

Code: Select all

target := "C:\Program Files\Google\Chrome\Application\chrome.exe" " https://www.autohotkey.com/docs/v2/lib/Run.htm"
...is the same as this:

Code: Select all

target := "C:\Program Files\Google\Chrome\Application\chrome.exe https://www.autohotkey.com/docs/v2/lib/Run.htm"

You are concatenating two literal strings with no real reason to have them separated with two pairs of quotation marks. If you want to have quotes as part of the strings, which is recommended for the Run function in case there are spaces in the paths (although these have no spaces), then you need quotes inside your quoted string like this:

Code: Select all

target := '"C:\Program Files\Google\Chrome\Application\chrome.exe" "https://www.autohotkey.com/docs/v2/lib/Run.htm"'

To see the differences/lack of differences:

Code: Select all

#Requires AutoHotkey v2.0
target1 := "C:\Program Files\Google\Chrome\Application\chrome.exe" " https://www.autohotkey.com/docs/v2/lib/Run.htm"
target2 := "C:\Program Files\Google\Chrome\Application\chrome.exe https://www.autohotkey.com/docs/v2/lib/Run.htm"
target3 := '"C:\Program Files\Google\Chrome\Application\chrome.exe" "https://www.autohotkey.com/docs/v2/lib/Run.htm"'
MyGui := Gui()
MyGui.SetFont('s12','Consolas')
MyGui.Add('Text',, target1 '`n' target2 '`n' target3)
MyGui.Show
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: How to start a program and hide it immediately?

18 Apr 2024, 20:06

boiler wrote:
18 Apr 2024, 16:49
....To see the differences/lack of differences:

Code: Select all

#Requires AutoHotkey v2.0
target1 := "C:\Program Files\Google\Chrome\Application\chrome.exe" " https://www.autohotkey.com/docs/v2/lib/Run.htm"
target2 := "C:\Program Files\Google\Chrome\Application\chrome.exe https://www.autohotkey.com/docs/v2/lib/Run.htm"
target3 := '"C:\Program Files\Google\Chrome\Application\chrome.exe" "https://www.autohotkey.com/docs/v2/lib/Run.htm"'
MyGui := Gui()
MyGui.SetFont('s12','Consolas')
MyGui.Add('Text',, target1 '`n' target2 '`n' target3)
MyGui.Show
Very nice!
Any thoughts on why the "Min" option isn't working?
ste(phen|ve) kunkel
User avatar
Noitalommi_2
Posts: 331
Joined: 16 Aug 2023, 10:58

Re: How to start a program and hide it immediately?

18 Apr 2024, 20:29

Hi.

@kunkel321
The Min option doesn't seem to work when Chrome was previously closed as maximized window.
User avatar
Noitalommi_2
Posts: 331
Joined: 16 Aug 2023, 10:58

Re: How to start a program and hide it immediately?

18 Apr 2024, 22:05

@Super Foxy

This hides the Chrome window but you have to wait until the window exists.
It didn't work for me without WainWait.

Code: Select all

Run("Chrome.exe",,,&pid)
WinWait("ahk_pid" pid)
WinHide
Sleep 1000
WinShow
Alternatively, without waiting, you could launch the Chrome window outside of the visible screen area.

Code: Select all

F1:: {

	global pid
	Run("Chrome.exe --window-position=0," A_ScreenHeight+100,,,&pid)
}
F2::WinMove(0, 0,,, "ahk_pid" pid)

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: wineguy and 58 guests