Guest dudecybetron Posted July 11, 2004 Share Posted July 11, 2004 hi, i found about autoit only by an accident.it seems a superb tool.i started to learn it but now there seems to be a problem.i coded a scirpt that intends to do the following. 1.whenever a blank notepad file is opened it will print the todays date and time to the first line of it. 2.it then changes the title from "Untitled - Notepad" to "Untile - Notepad" 3.if a user opens another file say "readme.txt then noting will hapen" i will give u the script that i coded but doesnt work as i xpected.may be am wrong.so u people please correct my mistake. autoitsetoption("wintitlematchmode",3) dim $one=0 while 1=1 while $one <> 1 winwaitactive("Untitled - Notepad" ) $one=1 wend $one=0 winsettitle("Untitled - Notepad","","Untitle - Notepad") send ("{F5}") wend u c here the date and time gets printed if i type notepad.exe and open a balnk notepad file.but the date and time again gets printed if i open someother notepad file say :readme.txt". hope people here will correct my mistake. Link to comment Share on other sites More sharing options...
Developers Jos Posted July 11, 2004 Developers Share Posted July 11, 2004 what about this way: AutoItSetOption(("WinTitleMatchMode", 3) While 1 = 1 If WinExists("Untitled - Notepad") Then WinSetTitle("Untitled - Notepad", "", "Untitle - Notepad") WinActivate("Untitle - Notepad") Send("{F5}") EndIf Sleep(10) Wend SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
pekster Posted July 11, 2004 Share Posted July 11, 2004 (edited) Edit: I didn't see JdeB's post when I started. Similar approaches though [/edit]It's not a mistake in your code, but how Windows changes the titles of windows. If you use notepad to open a file from within the application (ie: File --> Open) it will not paste the date and time in. However, if you double click a text file, the default title of "Untitled - Notepad" exists for a brief moment before the actual document title is reflected. Your script is actually detecting this change too quickly, and it presses the F5 key to paste in the date/ time. To fix this, you could take a WinWaitActive, and if it was true, wait 1 second, and do another WinWaitActive to insure that the title wasn't a temporary title while another document opened.I also see that your 2nd while loop is complealty useless; it could be replaced with just the WinWaitActive with no ill effects on your script. Try something like this instead:autoitsetoption("wintitlematchmode",3) while 1 winwaitactive("Untitled - Notepad" ) Sleep(1000) If WinGetTitle("") <> "Untitled - Notepad" Then ContinueLoop winsettitle("Untitled - Notepad","","Untitle - Notepad") send ("{F5}") wendPlay around with the delay if 1 second is too long; you can likely lower that quite a bit and have it still detect the window properly. Edited July 11, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
Guest dudecybetron Posted July 11, 2004 Share Posted July 11, 2004 hi folks, thanx a lot.so my script reads the title very fast and thats the cause for it.ok now i understand. Link to comment Share on other sites More sharing options...
pekster Posted July 11, 2004 Share Posted July 11, 2004 (edited) thanx a lot.so my script reads the title very fast and thats the cause for it.ok now i understand.Basically. Just slowing it down wouldn't help either because it could still happen that you detect it at just that point before the title changes.Minor edit Edited July 11, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
bobheart Posted July 11, 2004 Share Posted July 11, 2004 On my computer this work . autoitsetoption("wintitlematchmode",3) while 1 winwaitactive("Untitled - Notepad" ) Sleep(1000) If WinGetTitle("") <> "Untitled - Notepad" Then ContinueLoop winsettitle("Untitled - Notepad","","Untitle - Notepad") send ("{F5}") wend This gave me an error ? AutoItSetOption(("WinTitleMatchMode", 3) While 1 = 1 If WinExists("Untitled - Notepad") Then WinSetTitle("Untitled - Notepad", "", "Untitle - Notepad") WinActivate("Untitle - Notepad") Send("{F5}") EndIf Sleep(10) Wend Link to comment Share on other sites More sharing options...
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