lkalliance Posted March 22, 2011 Share Posted March 22, 2011 Hi, all, new to this site, this program, and in fact this kind of scripting in general (my background is in Javascript). I'm trying to learn my way around the program functions, and I've got some questions that are probably trivial to more experienced users. Here's what I'm trying to accomplish with a script that is to be turned into an executable and used by several people: (1) Launch Firefox. Might be in different locations based on the type of computer, OS, etc, so I have an opportunity for the user to put in an alternate path. This part appears to work. (2) Identify the launched window, and send it to a specified URL. This part has been problematic through many hours of trying to make it work. I can't anticipate the window title, as any given user's browser would default to an arbitrary website and thus have an arbitrary window name. I note that sending the command to Run("[user-supplied path]") creates a new instance of Firefox and activates it; however the keystroke "^l" (to select the URL field) is not registering. I think it's a race condition, but I've been banging my head against a wall trying to isolate the new (arbitrarily-titled) window to wait for it, activate it and send the keystrokes. My code keeps getting more and more convoluted, such as its current state: WinWait('[CLASS:MozillaUIWindowClass]') If WinExists('[LAST]') Then $origTitle = WinGetTitle('[LAST]') WinSetTitle($origTitle,'','New Firefox window') EndIf WinActivate('New Firefox window') WinWaitActive('New Firefox window') If WinActive('New Firefox window') Then Send('^l') Else MsgBox(0,"Firefox","The Firefox window is NOT active") EndIf I never get the message listed at the end, so either the script is breaking, or I am sending the ctrl-l keystroke into the ether, or something else. I've tried to insert MsgBoxes into the script to help step through and analyze the flow of data, but every time the MsgBox is being covered up by a newly-Activated window, as if the script is still running and not waiting for the MsgBox click. Should this be happening? Any help for this newbie would be extremely appreciated, thank you! Link to comment Share on other sites More sharing options...
Chimaera Posted March 22, 2011 Share Posted March 22, 2011 Maybe have a look at the firefox UDF which may helpThere are tools included in that which may assist in what you are trying to do If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Mallie99 Posted March 22, 2011 Share Posted March 22, 2011 First thought is that you may have better luck getting the Process ID from a RUN() command and using ProcessExists() functions? That way you are absolutely certain that the actual process is there. Mal Are you telling me something I need to know or something I want to know? Link to comment Share on other sites More sharing options...
lkalliance Posted March 22, 2011 Author Share Posted March 22, 2011 Maybe have a look at the firefox UDF which may helpThere are tools included in that which may assist in what you are trying to doI've actually downloaded the FF UDF and had no luck with it. I can confirm that the #include is working because I can output the version variable that's set, but no satisfactory outcome from _FFOpenURL. I'm ready to get back to that, once I am able to be sure I've isolated the window properly. Link to comment Share on other sites More sharing options...
lkalliance Posted March 22, 2011 Author Share Posted March 22, 2011 First thought is that you may have better luck getting the Process ID from a RUN() command and using ProcessExists() functions? That way you are absolutely certain that the actual process is there.MalI've thought of that! I know that the "Run" command does return a PID, and I can use "ProcessList" to get an array of processes at that moment, but I don't see a method in the documentation to link a process to a window. Is there some method I'm missing? Link to comment Share on other sites More sharing options...
Mallie99 Posted March 22, 2011 Share Posted March 22, 2011 I've thought of that! I know that the "Run" command does return a PID, and I can use "ProcessList" to get an array of processes at that moment, but I don't see a method in the documentation to link a process to a window. Is there some method I'm missing? As mentioned by Chimaera, the FF UDF may be your golden egg... Look at the _FFOpenURL function. As for why your script isn't working, my guess is down to it being loaded with WinWait and WinWaitActive function calls. This will just put the script to sleep all the time, hence my recommending the PID as a way out: $PID = Run(@ProgramFilesDir & "\Mozilla Firefox\Firefox.exe www.google.com", "C:\Temp", @SW_SHOW) While ProcessExists($PID) ; Execute Code ; Yadda yadda WEnd MsgBox(64,"Firefox", "Firefox is CLOSED") Mal Are you telling me something I need to know or something I want to know? Link to comment Share on other sites More sharing options...
lkalliance Posted March 22, 2011 Author Share Posted March 22, 2011 As mentioned by Chimaera, the FF UDF may be your golden egg... Look at the _FFOpenURL function. As for why your script isn't working, my guess is down to it being loaded with WinWait and WinWaitActive function calls. This will just put the script to sleep all the time, hence my recommending the PID as a way out: $PID = Run(@ProgramFilesDir & "\Mozilla Firefox\Firefox.exe www.google.com", "C:\Temp", @SW_SHOW) While ProcessExists($PID) ; Execute Code ; Yadda yadda WEnd MsgBox(64,"Firefox", "Firefox is CLOSED") Mal Ah, I see what you mean. There are still some concerns I have about this procedure (if there is already some other FF window open, won't I still need to isolate on the correct window? Is there a race condition between executing a process and the FF window that's created becomes active, for _FFOpenURL to work on?)...but I'll start down this path and see what I see. Thanks very much, you guys! Link to comment Share on other sites More sharing options...
Bert Posted March 22, 2011 Share Posted March 22, 2011 Did you install the AddOn MozRepl? You will need that in order for FF.au3 to work. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Dana Posted March 22, 2011 Share Posted March 22, 2011 Is Firefox the default browser? If so, how about this: $url = "http://xkcd.com" Run(@comspec & " /c start " & $url) Link to comment Share on other sites More sharing options...
lkalliance Posted March 22, 2011 Author Share Posted March 22, 2011 Did you install the AddOn MozRepl? You will need that in order for FF.au3 to work. Oops, have not. Will this be required for anyone that is using the executable? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted March 22, 2011 Share Posted March 22, 2011 Oops, have not. Will this be required for anyone that is using the executable?Yes. It's a Firefox add-on, it needs to be installed in every copy of Firefox. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
lkalliance Posted March 22, 2011 Author Share Posted March 22, 2011 FF.au3 isn't working for me. I can confirm that: --It's included in my script and the script can access it. --MozRepl is installed, set to "Activate on Startup" and running in my browser instance --The newly-launched window is active. I'm able to go to a URL by simply doing a "Send", though there are some default web pages that are race conditions (Google, for example, has to be fully loaded before I can Send, otherwise my text is captured by the search box, even if it has already started to be entered in the Address field). But when instead I use _FFOpenURL([variable containing full URL]) nothing happens. Link to comment Share on other sites More sharing options...
RichardL Posted March 23, 2011 Share Posted March 23, 2011 I think your mozrepl isn't working. See how to test it on mozrepl. On my work PCs something else had port 4242 and I had to use another. Richard 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