topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 7:04 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: AHK: Checking if Firefox has open tabs  (Read 8152 times)

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
    • View Profile
    • Donate to Member
AHK: Checking if Firefox has open tabs
« on: December 17, 2007, 04: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
    • View Profile
    • Donate to Member
Re: AHK: Checking if Firefox has open tabs
« Reply #1 on: December 17, 2007, 06:58 PM »
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..

ws-firefox-closetab.png
https://addons.mozil...S/firefox/addon/1122


nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
    • View Profile
    • Donate to Member
Re: AHK: Checking if Firefox has open tabs
« Reply #2 on: December 17, 2007, 11:55 PM »
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
    • View Profile
    • Donate to Member
Re: AHK: Checking if Firefox has open tabs
« Reply #3 on: December 18, 2007, 12: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)

; 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
    • View Profile
    • Donate to Member
Re: AHK: Checking if Firefox has open tabs
« Reply #4 on: December 18, 2007, 12: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
    • View Profile
    • Donate to Member
Re: AHK: Checking if Firefox has open tabs
« Reply #5 on: December 18, 2007, 07:28 PM »
you're welcome.. glad to be of help. :)