Jump to content

Really new at this


Recommended Posts

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

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

Maybe have a look at the firefox UDF which may help

There are tools included in that which may assist in what you are trying to do

I'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

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

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?

Link to comment
Share on other sites

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

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

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

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