DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: AHK: Checking if Firefox has open tabs  (Read 9,818 times)

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
AHK: Checking if Firefox has open tabs
« on: December 17, 2007, 10:35 AM »
I'm a total AutoHotKey novice but hashed up the following script to close apps with "numpad enter".
There are a couple of exceptions though, the calculator (which I don't want to close with numpadenter, for obvious reasons) and Firefox where I close the active tab, rather than the app itself.


NumpadEnter::

; Firefox gets a close tab command
    IfWinActive ,ahk_class MozillaUIWindowClass
    {      send ^w
            return
    }
    else

; Calc gets normal behavior for a numpad enter
    IfWinActive ,ahk_class CALCVIEWCLASS
    {    send {Enter}
          return
    }

; Send Alt+F4 to everything else
PostMessage, 0x112, 0xF060,,, A



I would additionally like to minimize Firefox if there is only a blank "Untitled" tab open, is there some hack to test for this?

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: AHK: Checking if Firefox has open tabs
« Reply #1 on: December 18, 2007, 12:58 AM »
nosh: you can achieve this via this add-on: Tab Mix Plus. install TMP and check the 3rd option as seen in the screenshot, now Firefox won't close if it's the last window/tab..

[attach=#]
• https://addons.mozilla.org/en-US/firefox/addon/1122

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
Re: AHK: Checking if Firefox has open tabs
« Reply #2 on: December 18, 2007, 05:55 AM »
Thanks Lanux, but I think you misunderstood me. I already have TMP installed and the "Do not close..." option is checked.
The script doesn't close Firefox in any case, but I want FF to minimize if there are no active tabs (i.e: just a blank tab: "Untitled").
 

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: AHK: Checking if Firefox has open tabs
« Reply #3 on: December 18, 2007, 06:15 AM »
nosh: i see your point here.. anyway, here's a script i did to see, whether this is possible and so here it is.. this AHK script monitors active Firefox windows and minimizes or send a Ctrl+W key-stroke. give this script a try and let me know if it is useful and also take note of the caveats mentioned in the comments section.. 8)

Code
; WatchFox - Sends keystroke based Firefox's condition
; assumes tabbed Firefox contains a hyphen in the Title-Bar while non-tabbed doesn't.
; can't differentiate when the Firefox window have blank tabs mixed with normal tabs. 
#Persistent
#SingleInstance force

SetTimer, WatchFox, 1500
Menu, Tray, Icon, %ProgramFiles%\Mozilla Firefox\firefox.exe, 1

WatchFox:
IfWinActive, ahk_class MozillaUIWindowClass
{
  WinGetActiveTitle, ActiveFox
  StringRight, OutputVar, ActiveFox, 17
  TabFox=-  ;use hyphen as the delimiter
  IfInString, OutputVar, %TabFox%
    Send, ^w
  Else
    WinMinimize
Sleep, 500
}
Return

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
Re: AHK: Checking if Firefox has open tabs
« Reply #4 on: December 18, 2007, 06:56 AM »
Lanux, nice!  :)

I didn't run the script as is but modded mine a bit and though I run FF with the title bar disabled, it works just fine. It's very rare that I would have blank tabs mixed with active ones so the caveat is quite acceptable. Thanks!  :Thmbsup:

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: AHK: Checking if Firefox has open tabs
« Reply #5 on: December 19, 2007, 01:28 AM »
you're welcome.. glad to be of help. :)

Original address: https://www.donationcoder.com/forum/index.php?topic=11359.0