ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

AHK: Checking if Firefox has open tabs

(1/2) > >>

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


• https://addons.mozilla.org/en-US/firefox/addon/1122

nosh:
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:
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:
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:

Navigation

[0] Message Index

[#] Next page

Go to full version