Jump to content

Im working through the tutorial and am stuck


Recommended Posts

Hi,

Im working my way through the tutorial fir AUTOIT.

 

I cant seem to get it to colse the notepad, the notepad just hangs there open.

 

here is the code.

run("Notepad.exe")
WinWaitActive("Untitled - Notepad")
send("This is some Text")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad","Do you want to save")
Send("!n")

 

 

Ive bet messing about with this for over an hour now, and something is worng.

 

Ive noticed , when notepad save, its saving as "*notpad" with a * on the front, this seems to be a problem, why is notepad prefixing with a *?

 

Link to comment
Share on other sites

26 minutes ago, charlie2charlie said:

Ive noticed , when notepad save, its saving as "*notpad" with a * on the front, this seems to be a problem,

you've got it !. So you are not stuck ;) 

 

26 minutes ago, charlie2charlie said:

this seems to be a problem, why is notepad prefixing with a *?

No clue. Updates ?  :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Hi, you should see and learn about Send function in Help file, the help file has a good example for your what you want:
 

Example()

Func Example()
    ; Simulate the key combination Win + R to open the Run dialogue window.
    Send("#r")

    ; Wait 10 seconds for the Run dialogue window to appear.
    WinWait("Run", "", 10)

    ; Simulate entering notepad.exe and pressing the 'ENTER' key.
    Send("notepad.exe{Enter}")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Simulate entering the following string and pressing the 'F5' key to input the date and time into edit control of Notepad.
    Send("Today's time/date is {F5}")

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

    ; Now a screen will pop up and ask to save the changes, the classname of the window is called
    ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")
EndFunc   ;==>Example

 

Link to comment
Share on other sites

The script below is the same as yours with 1 line added at the top.  By default, the title string has to be an exact match starting from the beginning of the window's title.  The asterisk (*) in the notepad title denotes that the file has been modified since it was last saved or created.  The OPT function that I added to the script says that the string you provide for the title can appear anywhere in the title.  If you use a -2, it will means it can appear anywhere in the title and is not case-sensitive.

Opt('WinTitleMatchMode', 2) ;1 = Start, 2 = SubString, 3 = Exact, 4 = Advanced, -1 to -4 = Case Insensitive.

run("Notepad.exe")
WinWaitActive("Untitled - Notepad")
send("This is some Text")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad","Save")
Send("!n")

 

*Updated example

Looks like there were a few changes to Notepad in Windows 10.  The Save dialog's visible text has changed.  The script above should work on Windows 10.  You can lookup each command in the Help file to see how and why it works.

Edited by TheXman
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...