Sign in to follow this  
Followers 0
Guest dudecybetron

am i wrong some where?

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Edit: I didn't see JdeB's post when I started. Similar approaches though :ph34r: [/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}")
wend

Play 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 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.

Share this post


Link to post
Share on other sites

hi folks,

thanx a lot.so my script reads the title very fast and thats the cause for it.ok now i understand.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0