1 ; This is a sample AutoIt script, based on the notepad1 sample script by Jonathan Bennett. 2 ; It runs notepad, enters some text and exits. 3 4 5 ; Exit with a nonzero exit status if the parameter equals 0. 6 ; This is useful for functions that return 0 upon failure. 7 Func Assert($n) 8 If $n = 0 Then Exit(1) 9 EndFunc 10 11 ; Wait for a window to exist, activate it, and wait for it to become active. 12 ; If timeout expires while waiting, exit with a nonzero exit status. 13 Func WaitForWindow($title, $text="", $timeout=60) 14 Assert(WinWait($title, $text, $timeout)) 15 WinActivate($title, $text) 16 Assert(WinWaitActive($title, $text, $timeout)) 17 EndFunc 18 19 ; Run Notepad 20 Assert(Run("notepad.exe")) 21 22 ; Wait up to 10 seconds for Notepad to become active -- 23 ; it is titled "Untitled - Notepad" on English systems 24 WaitForWindow("Untitled - Notepad", "", 10) 25 26 ; Now that the Notepad window is active type some text 27 Send("Hello from Notepad.{ENTER}1 2 3 4 5 6 7 8 9 10{ENTER}") 28 Sleep(500) 29 Send("+{UP 2}") 30 Sleep(500) 31 32 ; Now quit by pressing Alt-f and then x (File menu -> Exit) 33 Send("!f") 34 Send("x") 35 36 ; Now a screen will pop up and ask to save the changes, the window is called 37 ; "Notepad" and has some text "Yes" and "No" 38 WaitForWindow("Notepad", "", 10) 39 Send("n") 40 41 ; Now wait for Notepad to close before continuing 42 WinWaitClose("Untitled - Notepad", "", 10) 43 44 ; Finished! 45