Reputation: 21
I want to open 4 different chrome links, in 4 different windows, when my shortcut is pressed. Then it should resize the 4 windows so that one is top left corner, one top right corner, one bottom left corner and one in the bottom right corner. Does somebody know how i could do this
Ive tried this test code (example1 at the bottom) which should open a new chrome tab, resize it and move it to the top right corner, but it resizes it an moves it to the top right corner with a distance of around 50 pixels and all other chrometabs which are maximized get openend too because the if statement is valid for all chrometabs.
Does somebody have an idea how i could solve this problem?
example1
Run, chrome.exe
WinGet, WinStatus, MinMax, ahk_exe chrome.exe
if (WinStatus != 0)
WinRestore, ahk_exe chrome.exe
WinMove, ahk_exe chrome.exe,, 0, 0,
Upvotes: 1
Views: 1117
Reputation: 2344
I used the Windows directional arrow shortcuts to properly make the windows snap to the corners, since, as you noted, WinMove is a bit buggy for this.
Additionally, I found that the windows were easier and more reliable to position if you first open all of the windows before rearranging them (I used the hwnd/ ahk_id to keep track of each window after they were opened).
Finally, from modifying this, I was able to open a new chrome tab with a specified URL in a new window using the Run
command as follows.
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.example.com/"
Final Script:
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.google.com/"
topLeft:=WinExist("A")
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.example.com/"
topRight:=WinExist("A")
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.npr.org/"
bottomRight:=WinExist("A")
RunWait , "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window "https://www.bing.com/"
bottomLeft:=WinExist("A")
;https://stackoverflow.com/questions/23160472/open-chrome-in-windows-from-the-command-line-in-a-new-window
WinActivate, ahk_id %topLeft%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Left}{Up}{Lwin up}
Send {Esc}
Sleep 1000
WinActivate, ahk_id %topRight%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Right}{Up}{Lwin up}
Send {Esc}
Sleep 1000
WinActivate, ahk_id %bottomRight%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Left}{Down}{Lwin up}
Sleep 1000
Send {Esc}
WinActivate, ahk_id %bottomLeft%
WinMaximize
Sleep 100
Send {Lwin down}{Down}{Right}{Down}{Lwin up}
Send {Esc}
Sleep 1000
Note: Fiddle with or add Sleep
in between the commands as necessary to script optimize reliability.
Upvotes: 1