Sunday, November 18, 2018

command line - how to open file in window on set position using autohokey from cmd/batch?


I having a hard time to combine my scripts which work separately...


basicly I have a batch script with following in it:


START "" "mpc-hc64.exe" "video.avi"

this will open my video in mediaplayer. so far so good. then I had some reading on SO and SE about how to open window on set position via cmd/bat and found out in answers about AutoHotkey (documentation: here). so I downloaded a zip with executable and created a AHK script:


Run mpc-hc64.exe
WinWait, Media Player Classic Home Cinema
WinActivate
WinMove A,, 960, 0, A_ScreenWidth-960, A_ScreenHeight-29

this will open my mediaplayer at the right side of my screen if I run this cmd/bat:


AutoHotkeyU32.exe "script 1.ahk"

and now I would need to combine all above into one batch which if I run it thet it will open my video file in my mediaplayer and on the right side of my screen. can enyone help?


Answer



I found a way (on official discord AHK chanel):


#Persistent
mpc := "C:\T4\mpc-hc 1.7.16 x64\mpc-hc64.exe"
avi := "C:\T1\scripts\avi.avi"
Run, % """" mpc """ """ avi """", , , pid
WinWaitActive, % "ahk_pid " pid
WinGet, mpc_hwnd, ID, % "ahk_pid " pid
SetTimer, CheckWindowPosition, 100
CheckWindowPosition:
if(!WinExist("ahk_pid " pid)) {
ExitApp
}
WinGetPos, x, y, width, height, % "ahk_pid " pid
WinGet, hwnd, ID, % "ahk_pid " pid
if(DllCall("GetParent", "Ptr", hwnd, "UInt", 3) = 0 && DllCall("GetAncestor", "Ptr", hwnd, "UInt", 3) = mpc_hwnd) {
if(x != 960 || y != 0 || width != A_ScreenWidth - 960 || height != A_ScreenHeight - 29) {
WinMove, % "ahk_pid " pid, , 960, 0, % A_ScreenWidth - 960, % A_ScreenHeight - 29
}
}
return

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...