Fl4m3Ph03n1x Posted April 18, 2012 Posted April 18, 2012 (edited) Hey guys, I am a newbie to AutoIt, but I confess I got carried away by some of your examples. Lately I tried to change the Notepad Autoscript to make a Firefox test scrip that opens firefox and then closes it. My firefox is in PT language, but I don't think this is a problem because the shortcuts are correct. Can someone tell me what is wrong in my script please? ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) Local $answer = MsgBox(4, "AutoIt Example (English Only)", "This script will run Firefox and then quit. Run?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(0, "AutoIt", "OK. Bye!") Exit EndIf ; Run Firefox ShellExecute("C:Program FilesMozilla Firefoxfirefox.exe") ;MsgBox(0, "Debug Msg", "Running FF") ; Wait for the Firefox become active WinWaitActive("Firefox") MsgBox(0, "Debug Msg", "WinWait") ; Now quit by pressing Alt-f and then x (File menu -> Exit) Send("!f") Send("s") MsgBox(0, "Debug Msg", "Quitting FF") ; Now wait for Notepad to close before continuing WinWaitClose("Firefox") ; Finished! I also checked the API for WinWaitActive, but I don't get how I can use each one of the separate modes. Can someone help me understand what I have wrong? Thanks in advance! Edited April 18, 2012 by Fl4m3Ph03n1x
somdcomputerguy Posted April 18, 2012 Posted April 18, 2012 Put this at the top of your script: Opt("WinTitleMatchMode", 2) that'll probably resolve your issue. (look it up in the Help file for description) And, Welcome to the Forum! - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
bstjohn Posted April 18, 2012 Posted April 18, 2012 (edited) The default mode for WinTitleMatchMode will match a partial title string from the start. Check your Firefox title. I'll bet it starts with "Mozilla Firefox". So if you change your code to; Wait for the Firefox become active WinWaitActive("Mozilla Firefox")it will work.Now notice that your next statement is MsgBox.MsgBox(0, "Debug Msg", "WinWait") ; Now quit by pressing Alt-f and then x (File menu -> Exit) Send("!f") Send("s") MsgBox(0, "Debug Msg", "Quitting FF")This will steal focus and your Send commands won't go to Firefox. Before you issue Send commands, use WinActivate() to be sure your intended target gets the keystroke.MsgBox(0, "Debug Msg", "WinWait") ; Now quit by pressing Alt-f and then x (File menu -> Exit) WinActivate("Mozilla Firefox") "Send("!f") Send("s") ; BTW, shouldn't this be an "x"? MsgBox(0, "Debug Msg", "Quitting FF")Also, you can use Alt-F4 (Send("!{F4}") to exit most any Windows app. Edited April 18, 2012 by bstjohn
Bert Posted April 18, 2012 Posted April 18, 2012 You may want to look at this: The Vollatran project My blog: http://www.vollysinterestingshit.com/
Fl4m3Ph03n1x Posted April 18, 2012 Author Posted April 18, 2012 (edited) On 4/18/2012 at 1:10 PM, 'somdcomputerguy said: Put this at the top of your script: Opt("WinTitleMatchMode", 2) that'll probably resolve your issue. (look it up in the Help file for description) And, Welcome to the Forum! Thanks for the welcome! Btw, I tried that and it didn't work =( @bstjohn: I tried your solution but it didn't work :S It is ALT+S because S is for "Sair" which means "Exit" in PT/BR and PT/PT. Looks like you just learned a new word today I replaced it by ALT+F4 but I am still doing something wrong :S @Bellicus: Thanks for the link, but this is merely an academic exercise that I am failing to complete :S I am willing to learn, but I can't see what's wrong. I am also using MsgBox as a debug mechanism, is there a better way? New version: expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Windows 7 ; Author: Fl4m3Ph03n1x ; ; Script Function: ; Opens Firefix, and then quits. ; Opt("WinTitleMatchMode", 2) ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) Local $answer = MsgBox(4, "AutoIt Example (English Only)", "This script will run Firefox and then quit. Run?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(0, "AutoIt", "OK. Bye!") Exit EndIf ; Run Firefox ShellExecute("C:Program FilesMozilla Firefoxfirefox.exe") ; Wait for the Firefox become active WinWaitActive("Mozzila Firefox") ;MsgBox(0, "Debug Msg", "WinWait") ; Now quit by pressing Alt-f and then x (File menu -> Exit) WinActivate("Mozilla Firefox") Send("!{F4}") ;MsgBox(0, "Debug Msg", "Quitting FF") WinActivate("Mozilla Firefox") ; Now wait for Notepad to close before continuing WinWaitClose("Mozilla Firefox") ; Finished! Edited April 18, 2012 by Fl4m3Ph03n1x
somdcomputerguy Posted April 18, 2012 Posted April 18, 2012 Is that the code you're running? In the WinWaitActive line, you mispelled Mozilla. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Fl4m3Ph03n1x Posted April 18, 2012 Author Posted April 18, 2012 Will I be damned ... it actually worked. I am confused though, according to the tutorial it should have worked only with the word "Firefox" because "Mozilla Firefox" contains "Firefox". Oh well, I guess that's somehow related to Opt("WinTitleMatchMode", 2) which I don't fully understand. Thanks for the help guys! PS: Can I give you karma or something for the help?
somdcomputerguy Posted April 18, 2012 Posted April 18, 2012 (edited) AutoItSetOption Quote WinTitleMatchModeAlters the method that is used to match window titles during search operations.1 = Match the title from the start (default)2 = Match any substring in the title3 = Exact title match4 = Advanced mode, see <a href="../../../autoit3/docs/intro/windowsadvanced.htm">Window Titles & Text (Advanced)-1 to -4 = force lower case match according to other type of match. Edited April 18, 2012 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
bstjohn Posted April 19, 2012 Posted April 19, 2012 On 4/18/2012 at 7:44 PM, 'Fl4m3Ph03n1x said: It is ALT+S because S is for "Sair" which means "Exit" in PT/BR and PT/PT. Looks like you just learned a new word today Yes, it's a good day each day you learn something new!
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