Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AutoIt script to position window by name (will position Flash Player window by default)
; AutoIt script to position window by name (will position Flash Player window by default).
; Useful while working on flash projects with FlashDevelop for example, to position the debug window in the same position every launch.
; PositionWindow.exe <title> <mode> <x> <y> <interval>
; title: string to search in window title. Default is "Adobe Flash Player"
; mode: possible values. Default is "loop"
; - loop: will reposition every <interval> milliseconds
; - wait: will poll every <interval>ms until window appears then positions it once
; - once: just positions the window on execution
; x/y: pixels value or center. Defaults are 0
; interval: polling value in milliseconds. Default is 500
;
; Example: PositionWindow.exe VLC loop center center 2000
Func MoveFP($x, $y, $search)
Local $aList = WinList()
For $i = 1 To $aList[0][0]
If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
Local $title = $aList[$i][0]
If (StringInStr($title, $search)) Then
Local $size = WinGetClientSize($title)
If ($x == "center") Then
$x = (@DesktopWidth - $size[0]) / 2
EndIf
If ($y == "center") Then
$y = (@DesktopHeight - $size[1]) / 2
EndIf
WinMove($title, "", $x, $y)
Return True
EndIf
EndIf
Next
return False
EndFunc
Local $search = "Adobe Flash Player"
Local $mode = "loop"
Local $x = 0
Local $y = 0
Local $interval = 500
If $CmdLine[0] >= 1 Then
$search = $CmdLine[1]
If $CmdLine[0] >= 2 Then
$mode = $CmdLine[2]
EndIf
If $CmdLine[0] >= 4 Then
$x = $CmdLine[3]
$y = $CmdLine[4]
EndIf
If $CmdLine[0] >= 5 Then
$interval = $CmdLine[5]
EndIf
EndIf
If $mode == "loop" Then
While 1
MoveFP($x, $y, $search)
Sleep($interval)
WEnd
ElseIf $mode == "wait" Then
While Not MoveFP($x, $y, $search)
Sleep($interval)
WEnd
Else
MoveFP($x, $y, $search)
EndIf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment