Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Activating Chrome Tab


  • Please log in to reply
32 replies to this topic
hollyanswer
  • Guests
  • Last active:
  • Joined: --
Thank you very much! Sorry I am a newbie here... :)

Here is my fully code now; but not properly working :(
It's always openening a new tab with gmail.. Something wrong here?

WinActivate( TheWindowTitle, TheProgramTitle )
{
SetTitleMatchMode, 2
WinWaitActive - Google Chrome
ControlFocus, Chrome_RenderWidgetHostHWND1
Loop, 15
{
WinGetTitle, Title, A  ;get active window title
if(InStr(Title, "Gmail")>0){
   ;Found
  {
      break ; Terminate the loop
   }
   Send ^{Tab}
   Sleep, 50
  }
  
  ;NOT Found
ELSE{
   ;Open it - control t for a new tab
   Send, ^t
   Send, https://mail.google.com/mail/?shva=1#{Enter}
  {
      break ; Terminate the loop
   }
}}}


holly75
  • Members
  • 8 posts
  • Last active: Mar 07 2011 08:25 AM
  • Joined: 05 Mar 2011
Thank you very much! Sorry I am a newbie here...
(-> Very newbie: twice the same Question in this forum; sorry :))

Here is my fully code now; but not properly working
It's always openening a new tab with gmail.. Something wrong here?


WinActivate( TheWindowTitle, TheProgramTitle )
{
SetTitleMatchMode, 2
WinWaitActive - Google Chrome
ControlFocus, Chrome_RenderWidgetHostHWND1
Loop, 15
{
WinGetTitle, Title, A  ;get active window title
if(InStr(Title, "Gmail")>0){
   ;Found
  {
      break ; Terminate the loop
   }
   Send ^{Tab}
   Sleep, 50
  }
  
  ;NOT Found
ELSE{
   ;Open it - control t for a new tab
   Send, ^t
   Send, https://mail.google.com/mail/?shva=1#{Enter}
  {
      break ; Terminate the loop
   }
}}}


jkerr
  • Members
  • 5 posts
  • Last active: Jan 16 2014 01:11 AM
  • Joined: 13 May 2010
SetTitleMatchMode, 2



IfWinExist, - Google Chrome

{

   WinActivate ; use the window found above

   

   ;Click in the address bar

   MouseClick, left, 196, 59

      

   Loop, 15

   {

      WinGetTitle, Title, A  ;get active window title

      if(InStr(Title, "Gmail")>0)

      {

         ;Found

         break ; Terminate the loop

      }

      Send ^{Tab}

      Sleep, 50

   }

}else{

   ;launch google chrome

   Run, "C:\Documents and Settings\User\Local Settings\Application Data\Google\Chrome\Application\chrome.exe"

   Sleep, 3000

}



;Was the tab found?

WinGetTitle, Title, A  ;get active window title

if(InStr(Title, "Gmail")>0){

   ;Found

}else{

   ;Open it - control t for a new tab

   Send, ^t

   Send, https://mail.google.com/mail/?shva=1#{Enter}

}



holly75
  • Members
  • 8 posts
  • Last active: Mar 07 2011 08:25 AM
  • Joined: 05 Mar 2011
Aah thank you very much! You're my hero! :)

The only minor thing now: when there's no gmail tab in Chrome;
it makes about 5 loops through the tabs & after that: start the gmail-url.
I get a little seasick then.. ;)

Is it possible to start the gmail url directly?

(When the gmail tab is available: it works perfect.)

Oh and also it's better to use:

}else{
   Run, "https://mail.google.com/mail/?shva=1#"{Enter}
}}


holly75
  • Members
  • 8 posts
  • Last active: Mar 07 2011 08:25 AM
  • Joined: 05 Mar 2011
Mmmm... was cheering too early! :)

Two problems: What am I doing wrong?

1.With this code; Chrome freezes when it has to be started (no open Chrome window)

2. When Gmail has to be opened; (with open Chrome Window) a lot of tabs occur & then it opens gmail... the screen is flickering with tabs.

This is my code:


#SingleInstance force
SetTitleMatchMode, 2

WinActivate( TheWindowTitle, TheProgramTitle )
{
IfWinExist, - Google Chrome
{
   WinActivate ; use the window found above
   
   ;Click in the address bar
   MouseClick, left, 196, 59
      
   Loop, 15
   {
      WinGetTitle, Title, A  ;get active window title
      if(InStr(Title, "Gmail")>0)
      {
         ;Found
         break ; Terminate the loop
      }
      Send ^{Tab}
      Sleep, 50
   }
}else{
   ;launch google chrome
   Run, "C:\Users\holly\AppData\Local\Google\Chrome\Application\chrome.exe"
   Sleep, 3000
}

;Was the tab found?
WinGetTitle, Title, A  ;get active window title
if(InStr(Title, "Gmail")>0){
   ;Found
}else{
   Run, "https://mail.google.com/mail/?shva=1#"{Enter}
}}


jkerr
  • Members
  • 5 posts
  • Last active: Jan 16 2014 01:11 AM
  • Joined: 13 May 2010
At the bottom, you don't need to run chrome THEN check to see if gmail is open, just do the bottom command, which will do both.

As far as the tab switching/flickering, well, it's a hacky solution anyway... it loops through 15 tabs, or through 2 tabs 15 times...

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
for opening a new tab, note that sending ^t and typing the name works the same as running the path to chrome.exe with the url as the parameter. running chrome is more reliable too, as it works even if a program steals focus.

holly75
  • Members
  • 8 posts
  • Last active: Mar 07 2011 08:25 AM
  • Joined: 05 Mar 2011
Thank you for your quick answers.. can someone please please send me the full working code please? (Because I am a newbie; and I really want this to work:))

Cheers m8s!

holly75
  • Members
  • 8 posts
  • Last active: Mar 07 2011 08:25 AM
  • Joined: 05 Mar 2011
Please could someone help me: I have the following codes and it is not working:

The shortcut:
#a::WinActivate( "Gmail", "https://mail.google.com/mail/?shva=1#" )

And this lines for the WinActive function:

#SingleInstance force
SetTitleMatchMode, 2

WinActivate( TheWindowTitle, TheProgramTitle )
{
IfWinExist, - Google Chrome
{
   WinActivate ; use the window found above
      
   Loop, 15
   {
      WinGetTitle, Title, A  ;get active window title
      if(InStr(Title, "Gmail")>0)
      {
         ;Found
         break ; Terminate the loop
      }
      Send ^{Tab}
      Sleep, 50
   }
}else{
   ;launch google chrome
   Run %TheProgramTitle%
   Sleep, 3000
}}

It's not working; could someone please send me the correct codes please?
For both the correct shortcut and the correct WinActivate function.

Thank you very much!

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
"It's not working" ... Elaborate

holly75
  • Members
  • 8 posts
  • Last active: Mar 07 2011 08:25 AM
  • Joined: 05 Mar 2011
With this code; Chrome freezes when it has to be started (no open Chrome window) -> because the loop doesn't end I quess..

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
add a pause hotkey :?:

holly75
  • Members
  • 8 posts
  • Last active: Mar 07 2011 08:25 AM
  • Joined: 05 Mar 2011
Huurrraay! I have solved it... I was running Autohotkey in Windows 7 in Windows XP SP3 mode; I turned that off and and now it works like a charm..

Here is my code:

#a:: WinActivate( "Gmail", "http://mail.google.com/mail/" )

#SingleInstance force
SetTitleMatchMode, 2 

WinActivate( TheWindowTitle, TheProgramTitle )
{
IfWinExist, - Google Chrome
{
   WinActivate ; use the window found above
   
   ;Click in the address bar
   MouseClick, left, 196, 59
      
   Loop, 15
   {
      WinGetTitle, Title, A  ;get active window title
      if(InStr(Title, "Gmail")>0)
      {
         ;Found
         break ; Terminate the loop
      }
      Send ^{Tab}
      Sleep, 50
   }
}else

;Was the tab found?
WinGetTitle, Title, A  ;get active window title
if(InStr(Title, "Gmail")>0){
   ;Found
}else{
   Run, "https://mail.google.com/mail/?shva=1#"
}}


This code works for Google Chrome; if you want Internet explorer:
change the line:
IfWinExist, - Google Chrome
into
IfWinExist, - Windows Internet Explorer
That's all!

Cheers!

dcb_oz
  • Members
  • 1 posts
  • Last active: May 13 2011 01:31 AM
  • Joined: 13 May 2011
I've made a modification so that the script only checks each Chrome tab once. It assumes that if it hits the same tab name again, it has completed a loop. This prevents the sea-sickness noted earlier. Of course, if you have two tabs of the same name before you hit the Gmail tab, it will open a new Gmail tab.

I have also explicitly set SetTitleMatchMode to 2 as on my system it wasn't picking up the "- Google Chrome" at the end of the window title.

;
; Gmail
;
#a:: WinActivate( "Gmail", "http://mail.google.com/mail/" )

#SingleInstance force
SetTitleMatchMode, 2 

WinActivate( TheWindowTitle, TheProgramTitle )
{
	SetTitleMatchMode, 2
	IfWinExist, - Google Chrome
	{
	   	WinActivate ; use the window found above
   
		;Click in the address bar
		MouseClick, left, 196, 59
      
		WinGetTitle, Title, A  ;get active window title
		OrigTitle := Title 		
	
		Loop
		{
			if(InStr(Title, "Gmail")>0)
			{
				;Found
				break ; Terminate the loop
			}
			Send ^{Tab}
			Sleep, 50
			WinGetTitle, Title, A  ;get active window title
			if(Title = OrigTitle ) 
			{
				;Match to original title, assume all seen
				break			
			}
   		} 
	} 

	;Was the tab found?
	WinGetTitle, Title, A  ;get active window title
	if(InStr(Title, "Gmail")>0)
	{
		;Found
	} else {
		Run, "https://mail.google.com/mail/?shva=1#"
	}
}
return


Sako73
  • Guests
  • Last active:
  • Joined: --
Here is a slight tweak that accounts for having multiple Chrome windows open at once. It runs great on my Win 7 x64 system.

    chrome := "- Google Chrome"
    found := "false"
    tabSearch := "gmail.com - Gmail"
    curWinNum := 0
    
    SetTitleMatchMode, 2
    
    WinGet, numOfChrome, Count, %chrome% ; Get the number of chrome windows
    
    WinActivateBottom, %chrome% ; Activate the least recent window
    
    WinWaitActive %chrome% ; Wait until the window is active
    
    ControlFocus, Chrome_RenderWidgetHostHWND1 ; Set the focus to tab control ???
    
    ; Loop until all windows are tried, or until we find it
    while (curWinNum < numOfChrome and found = "false") { 
        WinGetTitle, firstTabTitle, A ; The initial tab title
        title := firstTabTitle
        Loop
        {
            if(InStr(title, tabSearch)>0){
                found := "true"
                break
            }
            Send {Ctrl down}{Tab}{Ctrl up}
            Sleep, 50
            WinGetTitle, title, A  ;get active window title
            if(title = firstTabTitle){
                break
            }
        }
        WinActivateBottom, %chrome%
        curWinNum := curWinNum + 1
    }
    
    ; If we did not find it, start it
    if(found = "false"){
        Run "https://gmail.com"
    }
    
    return