Exclude browsers from script.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

Exclude browsers from script.

04 Apr 2016, 06:27

Hello.
I have created a script to auto-arrange the windows of specific programs when they are active. The script works fine but I encountered a problem, when the windows title of my two browsers (Chrome/Firefox) have the same title (ie when I open the Steam store) they are auto-arranged as well. How can I avoid this?

I know I can use the ahk_exe parameter to distinguish the windows better, but I was wondering if there is a simpler,more generic way to accomplish this.
I tried the #IfWinNotActive ahk_class MozillaWindowClass parameter at the start of my script but with no result, the browsers still auto-arrange. here is my code:

Code: Select all

#Persistent
Settitlematchmode 2


SetTimer, check, 500
return


check:

GroupAdd, maximum, Google Chrome
GroupAdd, maximum, Task Manager
GroupAdd, maximum, ahk_exe uTorrent.exe
GroupAdd, maximum, JDownloader

GroupAdd, central, Steam
GroupAdd, central, Battle.net
GroupAdd, central, Origin
GroupAdd, central, Uplay
GroupAdd, central, Internet Download Manager
GroupAdd, central, Last.fm
GroupAdd, central, Skype

IfWinActive, ahk_group maximum
gosub, automax
IfWinActive, ahk_group central
gosub, autocenter
return


automax:
WinGetActiveTitle, title
WinGet, maximized, MinMax, %title%
if (maximized) = 0
WinMaximize, %title%
return


autocenter:
WinGetActiveTitle, title
WinGetPos,,, Width, Height, %title%
WinMove, %title%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: Exclude browsers from script.

04 Apr 2016, 07:23

I use the class names in my GroupAdd to group various browsers

Code: Select all

GroupAdd,BrowserGroup, ahk_class Chrome_WidgetWin_0   ;Chrome Browser
GroupAdd,BrowserGroup, ahk_class Chrome_WidgetWin_1   ;Chromium 20.x
GroupAdd,BrowserGroup, ahk_class Slimjet_WidgetWin_1  ;Slimjet browser
GroupAdd,BrowserGroup, ahk_class MozillaUIWindowClass ;Firefox Browser
GroupAdd,BrowserGroup, ahk_class MozillaWindowClass   ;Firefox 4 Browser
GroupAdd,BrowserGroup, ahk_class OpWindow             ;Opera Browser
GroupAdd,BrowserGroup, ahk_class OperaWindowClass     ;Opera 11
I don't know if anyone uses FF 4 anymore. n But I assume the same class name is used on FF 4 and later. :)
With the class names you don't have to worry what title may be in the caption bar.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

Re: Exclude browsers from script.

04 Apr 2016, 07:44

thanks but how do you tell the script to include my two groups and exclude the browsers group, while checking the active window?

For example I want a non-browser window with the title Steam to be centered but I dont want this to happen if it is a browser title.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Exclude browsers from script.

04 Apr 2016, 09:36

Try this: (untested}

Code: Select all

IfWinActive, ahk_group maximum
gosub, automax
Else IfWinActive, ahk_group central ; <<< add Else
gosub, autocenter
return
I hope that helps.
User avatar
KilliK
Posts: 255
Joined: 10 Mar 2016, 21:19

Re: Exclude browsers from script.

04 Apr 2016, 10:40

Thanks wolf_II but this is not what I am asking.
I dont want my script to be triggered when my browsers have the same window title with the ones I use as triggers for my applications.
For example, I want my Steam app to be centered but I dont want Chrome to be centered too when I visit the Steam page (because its window title has the same Steam word which triggers the script).
Right now whenever I visit Steam in my browser, the browser gets auto-centered, I want to avoid this.
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: Exclude browsers from script.

04 Apr 2016, 14:12

After using WinGetActiveTitle use WinGetClass to make sure the class of the window is not one of the browsers. For instance you could use an If statement as in If var in,classname1,classname2,etc. return. If you have a long list of class names then you could wrap the if statement into a function to avoid retyping all that etc..

See the help for If var [not] in/contains yadda yadda

Edit: Even better get the class name of the active window then return if it is not of interest.

Code: Select all

WinGetClass,class,A
If IsABrowserIUse(class)
  return
  ; ...  etc.
  
  IsABrowserIUse(ClassName)
  {
    If ClassName in,class1,class2,class3
      return true
    return false
    }
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest and 153 guests