forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewChromeWin.ahk
31 lines (25 loc) · 955 Bytes
/
NewChromeWin.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
; Open a new chrome window and get process ID
; wait until the window is ready to move
; For some reason the Chrome --window-size and --window-position arguments don't work
; https://autohotkey.com/boards/viewtopic.php?p=78778#p78778
NewChromeWin(x, y, w, h) {
chromeProcesses := ChromeProcessCount()
run, % "chrome.exe" ( winExist("ahk_class Chrome_WidgetWin_1") ? " --new-window " : " " ) url,,, WinPID
sleep 150
While(ChromeProcessCount() = chromeProcesses) {
}
chromeProcesses := ChromeProcessCount()
WinPID := LastChromeProcessId()
WinWait, % "ahk_pid " WinPID
WinMove, % "ahk_pid " WinPID,, x, y, w, h
return WinPID
}
; Determine how many Chrome processes are running
ChromeProcessCount() {
return ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name = 'chrome.exe'").Count()
}
LastChromeProcessId() {
WinGet, winId, IDLast, ahk_exe chrome.exe
WinGet, processId, PID, ahk_id %winId%
return processId
}