laurence77at Posted February 27, 2022 Posted February 27, 2022 Dear all, I am new to the forum. Can anyone show me how to run a command upon some text shows up in the status bar of a window? e.g. close the window/program when the status bar shows the word "finished". I tried: If Winexists ("[Finished]") Then Winclose ("Program - ", "") but then some error pops up like: if winexists ( - ^ error subscript used on non-accessible variable Perhaps my syntax is wrong? Thank you! Laurence
ad777 Posted February 27, 2022 Posted February 27, 2022 (edited) @laurence77at can you show image of window your using. just use StatusbarGetText:exsample below: #include <MsgBoxConstants.au3> Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc. Local $sText = StatusbarGetText("title of window here",'',$Part) MsgBox($MB_SYSTEMMODAL, "", "status bar says: " & $sText) & e.g. close the window/program when the status bar shows the word "finished": #include <MsgBoxConstants.au3> Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc. While 1 Local $sText = StatusbarGetText("title of window here",'',$Part) if $sText = "Finished" Then WinClose("Program - ","") ExitLoop Endif Sleep(50) Wend Edited February 27, 2022 by ad777 none
laurence77at Posted February 27, 2022 Author Posted February 27, 2022 Thanks ad777, Excellent. I guess the above loop will keep monitoring the status bar till the desired text appears? How about if the full text just contains the words "Finished"? (the status bar not exactly shows "Finished", but maybe something like "Finished at here or there", or only contains the words "Finished") if $sText = Thanks!
Nine Posted February 27, 2022 Posted February 27, 2022 StringInStr (see help file) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ad777 Posted February 27, 2022 Posted February 27, 2022 2 hours ago, laurence77at said: How about if the full text just contains the words "Finished"? (the status bar not exactly shows "Finished", but maybe something like "Finished at here or there", or only contains the words "Finished") if $sText = Thanks! Add StringInStr As @Nine Say's :See script below: #include <MsgBoxConstants.au3> Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc. While 1 Local $sText = StatusbarGetText("title of window here",'',$Part) Local $word = "Finished" if StringInStr($sText,$word) Then WinClose("Program - ","") ExitLoop Endif Sleep(50) Wend none
laurence77at Posted February 27, 2022 Author Posted February 27, 2022 It works. Many thanks to ad777 and Nine.
laurence77at Posted March 1, 2022 Author Posted March 1, 2022 Further to the above question, I want to further relax the criteria so that when the text appears in any part of the window, it works. I have tried to use Wingettext , but an error pops up: Local $Part = 1;The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc. While 1 Local $sText = WinGetText("Program",'',$Part) ; the below $word = and $sText = will make all text containing "finished" to function! Local $word = "Finished" if StringInStr($sText,$word) Then WinKill ("Program") ExitLoop EndIf Sleep(50) Wend Any idea? Thanks.
ad777 Posted March 1, 2022 Posted March 1, 2022 @laurence77at Next Time you should read help file. Url for WinGetText:https://www.autoitscript.com/autoit3/docs/functions/WinGetText.htm While 1 Local $sText = WinGetText("Program", '') ; the below $word = and $sText = will make all text containing "finished" to function! Local $word = "Finished" If StringInStr($sText, $word) Then WinKill("Program") ExitLoop EndIf Sleep(50) WEnd none
laurence77at Posted March 3, 2022 Author Posted March 3, 2022 Thanks. I am using the below call for opening an excel workbook, #include<excel.au3> Local $Var = "D:\workbook.xls" Local $oExcel_1 = _Excel_Open() _Excel_BookOpen($oExcel_1, $var) the book opened, but returned an autoit error: Line 227 (File "C:\Program Files\Autoit3\Include\Excel.au3 $oExcel.windows($oWorkbook.Name).Visible = $bVisible $oExcel.windows($oWorkbook.Name)^Error Error: Variable must be of type "Object", Any idea??
Nine Posted March 3, 2022 Posted March 3, 2022 Please use tags when you post code, as described in the previous link Your code is missing the assignment of $oWorkbook. Provide a runable code if you want us to test it... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
laurence77at Posted March 3, 2022 Author Posted March 3, 2022 (edited) Hi Nine, The code is there, it is just that simple - to open a excel workbook with a path and filename! I searched over and over the forum and help but still don't know why the error pops up, however, the file opened. I even tried the 'on error go to' you made earlier but to no avail.... Please help. #include<excel.au3> Local $Var = "D:\workbook.xls" Local $oExcel_1 = _Excel_Open() _Excel_BookOpen($oExcel_1, $var) Edited March 3, 2022 by laurence77at
junkew Posted March 5, 2022 Posted March 5, 2022 (edited) $oworkbook is not assigned a value as said before. Best advice is study examples in helpfile for functions you are using. Edited March 5, 2022 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
caramen Posted March 5, 2022 Posted March 5, 2022 This is a solution I get from this post : And I had this script from the topic : (Whitch helped me a lot in lot of similar situation.) It could react the same with your shell console. You have to redefine the code as you need. expandcollapse popup#include <constants.au3> #include <string.au3> #RequireAdmin ; Use RunAs if you want use a fixed username/password within the script: ; Global $hPowerShellPID = RunAs("UserName", "Domain", "Password", "", "powershell.exe", '', @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_MERGED)) ; or use #RequireAdmin and a simple Run Statement to enter Admin credentials (if needed) at runtime ; Here we start a "permanent" powershell prompt with redirected streams Global $hPowerShellPID = Run("powershell.exe", '', @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_MERGED)) ; this little loop is to wait for the "welcome" message from powershell ; just a way to be sure that the powershell is running and "streaming" Do StdoutRead($hPowerShellPID) Until @extended ; out stream started ; example: ; Here we "execute a command via the Powershell that is running in background... ; ...and we get back to resulting output Local $Out = _Run_Cmdlet("Get-ItemPropertyValue 'Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' -Name 'EnableLUA'", $hPowerShellPID) ConsoleWrite($Out) ; here another command ConsoleWrite(_Run_Cmdlet("dir c:\", $hPowerShellPID)) ; .... and so on ... ; this function execute the passed powershell command and returns the resulting output Func _Run_Cmdlet($sCmd, ByRef $hPS) Local $sStdOut = '' ; we insert a start and an end message in order to identify the "body" of the result of the command executed $sCmd = 'write-host "->StartOfStream<-"; ' & $sCmd & '; write-host "->EndOfStream<-"' & @CRLF StdinWrite($hPS, $sCmd) Do Sleep(250) $sStdOut &= StdoutRead($hPS) ; the presence of the known end message signals the end of the execution Until StringInStr($sStdOut, "->EndOfStream<-" & @LF) ; return only the body of the outpu of the passed command Return _StringBetween($sStdOut, "->StartOfStream<-" & @LF, "->EndOfStream<-" & @LF)[0] EndFunc ;==>_Run_Cmdlet I'm sure you could done your goal with this Enjoy. Thanks @Gianni btw. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
laurence77at Posted March 10, 2022 Author Posted March 10, 2022 Thank you Junkew and Caramen, I finally found the below post that solved the "bug": Simply by changing the Excel.au3 with the updated code avoided the error. Should this be included in the include folder in future autoit releases? Thanks.
junkew Posted March 10, 2022 Posted March 10, 2022 I am not sure what you did but this should have been enough $oWorkbook=_Excel_BookOpen($oExcel_1, $var) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now