#cs ---------------------------------------------------------------------------- Program: CloseOODoc Version: See $Versions variable AutoIt Ver: 3.3.10 Usage: Pass a parameter via command line as Window title to close Pass a 2nd parameter (optional) to specify ms to pause before executing close. Default is 1000ms (1s) Description: Requires: #ce ---------------------------------------------------------------------------- #include #include ; Global constants Global Const $gcAppName = "CloseOODoc" Global Const $gcVersion = "1.1" Global Const $gcCopyright = "GPL 2014 - HHHz Software" Global $gCmdWinTitle = "" Global Const $gcSaveTitle = "OpenOffice" Global $gAppTitle = $gcAppName & " v" & $gcVersion ; Get 1st parameter as title If $CmdLine[0] < 1 Then MsgBox($MB_ICONERROR, $gcAppName, "This program needs one parameter to match as title!") Exit EndIf $gCmdWinTitle = $CmdLine[1] If $CmdLine[0] >= 2 Then $gSleepTime = $CmdLine[2] Else $gSleepTime = 1000 EndIf Sleep($gSleepTime) ; sleep a little to make sure OpenOffice macro ends first If WinExists($gCmdWinTitle) Then Local $hWnd = WinGetHandle($gCmdWinTitle, "") WinClose($hWnd) Local $aWinList = WinList("[CLASS:SALSUBFRAME]") Local $hWnd2 Local $bFound = False For $i = 1 to $aWinList[0][0] ; first item is count If StringLeft($aWinList[$i][0], StringLen($gcSaveTitle)) = $gcSaveTitle And _ BitAND(WinGetState($aWinList[$i][1]), 2) Then ; Title matches and is visible, assume we found it... ; hopefully there isn't more than 1 $hWnd2 = $aWinList[$i][1] WinActivate($hWnd2) ;_HH_DbgMsg("Got save message") Send("!D") ; Alt-D (discard anything to save) ;_HH_DbgMsg("Disregarded save message, window closed, exiting.") $bFound = True ExitLoop EndIf Next If not $bFound Then ;_HH_DbgMsg("No save message, window closed, exiting.") EndIf Else ;_HH_DbgMsg("Window not found") EndIf