Advertisement
wwww

ww AHK Firefox New Window

Jan 23rd, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  3. #Warn  ; Recommended for catching common errors.
  4. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  5. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  6. CoordMode, Mouse, Screen
  7. SetBatchLines, -1
  8. SetWinDelay, -1
  9.  
  10. FirefoxClass := "MozillaWindowClass"
  11. FirefoxLocation := "C:\Program Files (x86)\Aurora\firefox.exe"
  12. FirefoxWorkingDir := ""
  13. X := 50
  14. Y := 50
  15. W := 300
  16. H := 300
  17.  
  18. !f::
  19.     WinGet, WinId,, % "ahk_class" . FirefoxClass
  20.     IfWinActive, % "ahk_id" . WinId
  21.     {
  22.         WinGet, NextWinId, IDLast, % "ahk_class" . FirefoxClass
  23.         If (WinId = NextWinId) ; Only one window is active
  24.         {
  25.             WinMove, % "ahk_id" . RunAndWait(FirefoxLocation, FirefoxWorkingDir, "ahk_class" . FirefoxClass),, % X, % Y, % W, % H
  26.             Return
  27.         }
  28.         Else
  29.         {
  30.             WinActivate, % "ahk_id" . NextWinId
  31.             Return
  32.         }
  33.     }
  34.     Else
  35.     {
  36.         IfWinExist, % "ahk_id" . WinId
  37.         {
  38.             WinActivate, % "ahk_id" . WinId
  39.             Return
  40.         }
  41.         Else
  42.         {
  43.             Run, % FirefoxLocation, % FirefoxWorkingDir
  44.             Return
  45.         }
  46.     }
  47. Return
  48.  
  49. RunAndWait(Location, WorkingDir, WinTitle)
  50. {
  51.     WinGet, CurrWinCount, Count, % WinTitle
  52.     TargetWinCount := CurrWinCount + 1
  53.     Run, % Location, % WorkingDir
  54.     Count := 0
  55.     While (CurrWinCount < TargetWinCount)
  56.     {
  57.         Sleep, 100
  58.         WinGet, CurrWinCount, Count, % WinTitle
  59.         Count := Count + 1
  60.         If (Count > 600) ; One minute has passed
  61.         {
  62.             Return 0
  63.         }
  64.     }
  65.     WinGet, NewWinId,, % WinTitle
  66.     Return NewWinId
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement