0

I have a simple AHK script that opens a website in my default browser (Firefox).

NumPad7::
    Run, www.bbc.com 
return

When I run the program outside of Firefox, it opens the website in a new tab as intended. However, when I am in Firefox and run the script, Firefox is deactivated although the website does open. If I use the hotkey an even number of times it works even when Firefox is open. I have tried using WinActivate after the command but it doesn't work.

Any idea how I can keep Firefox active?

4
  • Try adding WinWait before WinActivate. Does it occur in all websites you want open this way? Commented Jan 26, 2019 at 9:54
  • @user3419297 I tried WinWait and WinWait[not]Active before WinActivate, neither worked with any of the sites I tried. Commented Jan 26, 2019 at 9:57
  • Do not use WinWaitActive before WinActivate. And what happens if you use another key instead of NumPad7 e.g. F1? Commented Jan 26, 2019 at 10:05
  • @user3419297 Same problem with any other key. I was using WinWaitNotActive, hoping the window would become inactive and then I could activate it again. Commented Jan 26, 2019 at 10:07

1 Answer 1

1

Try to find out which window gets active, this way:

NumPad7::
    Run, www.bbc.com 
    Sleep 500 ; or more
    WinGetTitle, WinTitle, A
    WinGetClass, ActiveClass, A
    MsgBox, Active Window:`n"%WinTitle%"`nahk_class "%ActiveClass%"
return

And this should work:

NumPad7::
    Run, www.bbc.com 
    WinWait, BBC - Homepage - Mozilla Firefox
    WinActivate, BBC - Homepage - Mozilla Firefox
return
Sign up to request clarification or add additional context in comments.

3 Comments

Helpful, but it doesn't work on my machine :(. The message box is printing "" for the title when it doesn't make the window active and printing BBC - Homepage - Mozilla Firefox when it makes the window active.
Same on my machine, nevertheless the second code works for me (the window remains active after WinActivate). Isn't this what you wanted? You can add WinWaitActive after WinActivate, but only if you want that the script takes another action upon the active window.
Yes, that is what I wanted but it doesn't always happen. Sometimes the firefox window remains active and sometimes it doesn't (try opening multiple tabs). So strange.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.