hima Posted May 2, 2014 Share Posted May 2, 2014 Hi, I have written a test script to open a notepad document, send some text and close it. It executes only once. I close that document by clicking on the X button. The second time I run it, it doesnt open another notepad document. Could you please advice? Link to comment Share on other sites More sharing options...
JohnOne Posted May 2, 2014 Share Posted May 2, 2014 Sure. Post your script. Alok_Arora 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
hima Posted May 2, 2014 Author Share Posted May 2, 2014 #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.10.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here Run ("notepad.exe") WinWaitActive("Untitled - Notepad") Send("This is some text" & "This is on a new line! ") WinClose("Untitled - Notepad") WinWaitActive("Notepad","Do you want to save") Send("!n") Thank you for replying. This is the script I am trying to execute. Link to comment Share on other sites More sharing options...
hima Posted May 2, 2014 Author Share Posted May 2, 2014 I am able to run it by double clicking on the script. When I try to run it from SciTE using F5, it doesnt execute more than once. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 2, 2014 Moderators Share Posted May 2, 2014 That is because it doesn't complete, it is stuck waiting at the following line: WinWaitActive("Notepad","Do you want to save") Try this instead: Run ("notepad.exe") WinWaitActive("Untitled - Notepad") Send("This is some text" & "This is on a new line! ") WinClose("Untitled - Notepad") WinWaitActive("Notepad", "") Send("!n") "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
hima Posted May 2, 2014 Author Share Posted May 2, 2014 I changed the script to : Run ("notepad.exe") WinWaitActive("Untitled - Notepad") Send("This is some text" & "This is on a new line! ") WinClose("Untitled - Notepad") WinWaitActive("Notepad", "") Send("!n") Its the same. I am able to run it by double clicking. Tools --> Go in SciTE is grayed out. Link to comment Share on other sites More sharing options...
hima Posted May 2, 2014 Author Share Posted May 2, 2014 Not sure how, it started working now. When I press F5, its getting executed everytime. What I noticed what there were many scripts running in the system tray. When I closed all of them, it started working. Is it a bug. Or am I doing something incorrectly. Has anyone come across such an issue? Link to comment Share on other sites More sharing options...
hima Posted May 2, 2014 Author Share Posted May 2, 2014 I changed the script back to : Run ("notepad.exe") WinWaitActive("Untitled - Notepad") Send("This is some text" & "This is on a new line! ") WinClose("Untitled - Notepad") WinWaitActive("Notepad","Do you want to save") Send("!n") And I am facing the same issue again. what does adding "Do you want to save" do there? How does it get stuck there. Link to comment Share on other sites More sharing options...
jdelaney Posted May 2, 2014 Share Posted May 2, 2014 (edited) When you have multiple scripts interacting with the same application, with indefinite waits, it's first come first serve. So, your particular run may not be the executor, and then waits until it can be. This is not a bug, and expected, given how you scripted. edit: your particurlar reason for failure, is that the text you think is visible, is not (on the do you want to save window). It's probably painted, or on child window of the popup. Run ("notepad.exe") WinWaitActive("Untitled - Notepad") Send("This is some text" & "This is on a new line! ") WinClose("Untitled - Notepad") WinWaitActive("[TITLE:Notepad;CLASS:#32770]") Send("!n") I would do something more like this, but even then, I would grab the window based on the PID of the Run, and not just blindly wait for any notepad window $pid = Run ("notepad.exe") $hwnd = WinWaitActive("Untitled - Notepad") ControlSend($hwnd,"","Edit1", "This is some text" & @CRLF & "This is on a new line! ") WinClose("Untitled - Notepad") $hwnd2 = WinWaitActive("[TITLE:Notepad;CLASS:#32770]") ControlClick($hwnd2,"","[CLASS:Button;TEXT:Do&n't Save]") Better still: expandcollapse popup#include <WinAPI.au3> $pid = Run ("notepad.exe") $hwnd = GetWindowMatchingProcess ($pid,"[CLASS:Notepad]") If Not IsHWnd($hwnd) Then ConsoleWrite("Unable to find window in time" & @crlf) Exit 1 EndIf WinActivate($hwnd) $hControl = ControlGetHandle($hwnd,"","Edit1") ControlSend($hwnd,"",$hControl, "This is some text" & @CRLF & "This is on a new line! ") WinClose($hwnd) $hwnd2 = WaitForEnabledPopup($hwnd) If Not IsHWnd($hwnd2) Then ConsoleWrite("Unable to find popup in time" & @crlf) Exit 1 EndIf ControlClick($hwnd2,"","[CLASS:Button;TEXT:Do&n't Save]") Exit 0 Func GetWindowMatchingProcess($pid,$windowID,$iMaxWaitMilliSec = 2000) $iTimer = TimerInit() While TimerDiff($iTimer)<$iMaxWaitMilliSec $aWin = WinList($windowID) For $i = 0 To UBound($aWin)-1 Local $tempPid = "" _WinAPI_GetWindowThreadProcessId($aWin[$i][1],$tempPid) If $tempPid = $pid Then Return $aWin[$i][1] EndIf Next Sleep (100) WEnd Return False EndFunc Func WaitForEnabledPopup($hWin,$iMaxWaitMilliSec = 2000) $hPopup = "" $iTimer = TimerInit() While TimerDiff($iTimer)<$iMaxWaitMilliSec $hPopup = _WinAPI_GetWindow($hWin,6) If IsHWnd($hPopup) Then Return $hPopup EndIf WEnd Return False EndFunc Edited May 2, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
czardas Posted May 2, 2014 Share Posted May 2, 2014 (edited) If the GO menu item is greyed out, then there is a script still running which needs to be terminated. I'll hazard a guess that if you click on SciTE before the script terminates, the SciTE interface steals focus from notepad causing the script to hang waiting for the save dialog to become active (although it might be something else). I can't test this theory right now because I'm not on windows ATM, so don't quote me on this. Edited May 2, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
hima Posted May 5, 2014 Author Share Posted May 5, 2014 (edited) Thank you for helping, everyone. It works now. Edited May 5, 2014 by himaggi Link to comment Share on other sites More sharing options...
Alok_Arora Posted July 8, 2020 Share Posted July 8, 2020 (edited) On 5/2/2014 at 2:49 PM, JohnOne said: Sure. Post your script. Hello Sir, My email id is *snip* Need your help.. Very hopeful from you sir, kindly reply for this.. Want the code for below Scenario If a script is run once in a day it should not run twice that day. I have the logic, like script will search the Log file and if the same entry is available for the day for that task script will pop up a message that "task already run" and close the script. Edited July 8, 2020 by Jos Link to comment Share on other sites More sharing options...
Alok_Arora Posted July 8, 2020 Share Posted July 8, 2020 (edited) Hello Friends, My email id is *snip* Need your help.. Very hopeful from you all, kindly reply for this.. Want the code for below Scenario If a script is run once in a day it should not run twice that day. I have the logic, like script will search the Log file and if the same entry is available for the day for that task script will pop up a message that "task already run" and close the script. If the log file is excel file than it is best. Edited July 8, 2020 by Jos Link to comment Share on other sites More sharing options...
Alok_Arora Posted July 8, 2020 Share Posted July 8, 2020 (edited) Hello Friends, My email id is *snip* Need your help.. Very hopeful from you all, kindly reply for this.. Want the code for below Scenario If a script is run once in a day it should not run twice that day. I have the logic, like script will search in Log file and if the same entry is available for the day for that task script will pop up a message that "task already run" and close the script If the log file is excel file than it is best. Edited July 8, 2020 by Jos Link to comment Share on other sites More sharing options...
water Posted July 8, 2020 Share Posted July 8, 2020 Welcome to AutoIt and the forum! You could simply store the date of the last successful run in a file (that only holds this date). Read this file to into a variable and compare to the current date ... voilá My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
jchd Posted July 8, 2020 Share Posted July 8, 2020 (edited) Are you going to spam every forum section and old irrelated posts for long? Do what @water said that I didn't have enough time to type before he posted. Edited July 8, 2020 by jchd seadoggie01 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
water Posted July 8, 2020 Share Posted July 8, 2020 You noticed that this topic is more than 6 years old and that the OP has been absent for this time? So don't hold your breath for a reply. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
argumentum Posted July 8, 2020 Share Posted July 8, 2020 Your answer is here. But I like the call for friends ( Hope you get to code something someday. It's so cool to code. ) Oh, do remove your email !. Is a very bad idea to post such thing publicly. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Alok_Arora Posted July 8, 2020 Share Posted July 8, 2020 10 minutes ago, water said: You noticed that this topic is more than 6 years old and that the OP has been absent for this time? So don't hold your breath for a reply. I still hope that someone will help me. I need this code badly friend. Link to comment Share on other sites More sharing options...
Danp2 Posted July 8, 2020 Share Posted July 8, 2020 3 minutes ago, argumentum said: Oh, do remove your email !. Is a very bad idea to post such thing publicly Too late... I already signed him up for thousands of sites via MailBait! argumentum 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Recommended Posts