is it possible to write a script that opens specific chrome or firefox tabs Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
sleepy

is it possible to write a script that opens specific chrome or firefox tabs  Topic is solved

04 Jan 2017, 19:13

like ctrl+a opens the second tab etc

also is it possible to write a script that opens a tab or web page based on a sequence i.e. ctrl+a then press "g"
huge thank you, not sure if AHK is appropriate for this.
User avatar
Brazolek123
Posts: 163
Joined: 06 Jun 2016, 16:02

Re: is it possible to write a script that opens specific chrome or firefox tabs

04 Jan 2017, 20:00

Well, if you know title of the tab you want to open you can just use https://autohotkey.com/docs/commands/WinActivate.htm (each opened tab has a different title in Chrome, not sure if other browsers works the same way). You also can open a website using command https://autohotkey.com/docs/commands/Run.htm, even when there is no web browser turned on.
You can also send key or combination of keys directly to desired window using https://autohotkey.com/docs/commands/ControlSend.htm.

Using 'Active window info' tool to obtain window title or class also might be helpful in your case.
sleepy

Re: is it possible to write a script that opens specific chrome or firefox tabs

04 Jan 2017, 20:12

turns i don't need a sequence of keys anymore..my main priority is to be able to open many different tabs...with ctrl+a ctrl+g etc...

someone on reddit suggested this:

#SingleInstance, Force
#IfWinActive, ahk_exe chrome.exe
^a::Send, ^2

works great until I try a larger numbered tab, like say 11...takes me to tab 1

i'm looking into winactivate now. thank you
sleepy

Re: is it possible to write a script that opens specific chrome or firefox tabs

04 Jan 2017, 22:21

I already know the titles to the exact tabs I would like to open

Is there an example somehwere of how to use Winactivate with chrome?
User avatar
Brazolek123
Posts: 163
Joined: 06 Jun 2016, 16:02

Re: is it possible to write a script that opens specific chrome or firefox tabs

05 Jan 2017, 04:44

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

title = is it possible to write a script that opens specific chrome or firefox tabs - AutoHotkey Community - Google Chrome

f1::
	WinActivate, %title%
return

f12::
	ExitApp
sleepyswallow
Posts: 8
Joined: 04 Jan 2017, 18:56

Re: is it possible to write a script that opens specific chrome or firefox tabs

05 Jan 2017, 10:44

hello,

I pasted the above script exactly, without changing an line...leaving this tab open and it did not work

Am I missing something obvious? Using w7, if that makes any difference
sleepyswallow
Posts: 8
Joined: 04 Jan 2017, 18:56

Re: is it possible to write a script that opens specific chrome or firefox tabs

05 Jan 2017, 11:08

nevermind, it's not possible to do this in different chrome tabs, just windows?
sleepyswallow
Posts: 8
Joined: 04 Jan 2017, 18:56

Re: is it possible to write a script that opens specific chrome or firefox tabs

05 Jan 2017, 14:23

WinActivate, ahk_id %VarContainingID%

this works but not with chrome tabs, which is weird because in task manager each tab has it's own PID
User avatar
Nextron
Posts: 1274
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: is it possible to write a script that opens specific chrome or firefox tabs

05 Jan 2017, 16:32

Each tab runs in its own (windowless) process, but they are displayed by a single parent process. So you can't activate a tab by activating the process.

Using browser's native hotkeys, Ctrl+1-8 activate tab 1-8 and Ctrl+9 activates the last tab. If you want to activate one beyond those, you're stuck with activating the one closest to it (either 8 or the last) and using Ctrl+Tab multiple times to move one tab forward or Ctrl+Shift+Tab to move back. If you know the number of the tab you just send the correct amount of presses. If you don't, you Loop %MaxTabs% it Until WinActive("tab title").

A more elaborate way would be to use ACC to actually read the tab name without activating them and clicking the right one, but that's more difficult and probably doesn't work well once you have so many the tab bar is scrollable.


Also, please edit your post with updates if your the last and recent poster instead of quadruple posting :shock:
sleepyswallow
Posts: 8
Joined: 04 Jan 2017, 18:56

Re: is it possible to write a script that opens specific chrome or firefox tabs

05 Jan 2017, 17:21

thanks, sorry. I'm a bit stressed out. lol.

So I was thinking a "cheat" I could do is have the tabs preloaded in firefox and chrome, that would give me 18 tabs...IE, if I'm desparate

I wrote this which works..need to remember 9 isn't the 9th tab, just the LAST tab.

sorry, a bit braindead right now. I'm not a programmer obviously.


#SingleInstance, Force

#IfWinActive, ahk_exe chrome.exe

^a::Send, ^1
^b::Send, ^2
^c::Send, ^3
^d::Send, ^4
^e::Send, ^5
^f::Send, ^6
^g::Send, ^7
^h::Send, ^8
^i::Send, ^9



#IfWinActive, ahk_exe firefox.exe

^j::Send, ^1
^k::Send, ^2
^l::Send, ^3
^m::Send, ^4
^n::Send, ^5
^o::Send, ^6
^p::Send, ^7
^q::Send, ^8
^r::Send, ^9


UPDATE
^^^^^^^^^^^^^
inspired my solution. im making multiple chrome profiles, ctrl+shift+m to toggle profiles then ctrl+1..ctrl+2 etc. not using ahk unless i feel like switching to ctrl+a etc
otravers
Posts: 1
Joined: 13 Jan 2017, 09:48

Re: is it possible to write a script that opens specific chrome or firefox tabs

13 Jan 2017, 10:10

Based on a thread in the old forum:
https://autohotkey.com/board/topic/5025 ... tab/page-3

Here's what I currently have, based not on tab numbers but specific sites/web apps that I want to switch to:

Code: Select all

#g::WinActivate( "- Gmail", "https://mail.google.com/mail/u/0/#inbox" )
#t::WinActivate( "Todoist", "https://todoist.com/app?lang=en" )
#y::
	WinActivate( " - YouTube", "https://www.youtube.com/feed/subscriptions" )
	Send {Space}
return

WinActivate( TheWindowTitle, TheProgramTitle ) {
	if (TheWindowTitle = " - YouTube")
	{
		chrome := TheWindowTitle
	}
	else
	{
		chrome := " - Google Chrome"
	}

	found := "false"
	tabSearch := TheWindowTitle
	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}
			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"){
		WinActivateBottom, %chrome%
		curWinNum := curWinNum + 1
		Run %TheProgramTitle%
	}
	return
}

Edit: the code above now recognizes popups (hard-coded to YouTube at the moment) as well as regular tabs. The former don't include " - Google Chrome" in the Window Title (it appears popups just use the page's HTML title tag and website name), even though according to Chrome's task manager, popups are really tab processes. It happens that I like to run Youtube in a popup as I explained in this post:
http://www.oliviertravers.com/how-youtube-window/

I'm sure this could be refactored to cycle through popups then tabs so that it's not necessary to hard-code anything (that way I could put Gmail and Todoist in popups).

Anyway this might be a bit of a digression vs. your original request (by tab number) but I hope this helps.
User avatar
jeeswg
Posts: 5290
Joined: 19 Dec 2016, 01:58
Location: UK

Re: is it possible to write a script that opens specific chrome or firefox tabs

13 Jan 2017, 20:32

AccViewer can retrieve the names of Firefox browser tabs,
and so it should be possible to check if a tab
with a certain name exists,
and to click a tab with a specific name via accDoDefaultAction.

However, although I could retrieve information via AccViewer,
I have been having trouble retrieving this information via Acc.ahk.
Any help would be much appreciated, as I keep running into this problem,
with different programs, AccViewer works,
but Acc.ahk functions appear to be inconsistent,
working on some programs but not others.

The same was true of Chrome, I could retrieve information via AccViewer,
but not obtain it via the Acc functions in Acc.ahk.

To open a url in a new tab is quite straightforward:

Code: Select all

vPath := "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
Run, "%vPath%" "%vUrl%"
vPath := "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Run, "%vPath%" "%vUrl%"
For Firefox, initial get tab names attempt:

Code: Select all

WinGet, hWnd, ID, A

;this works
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
vOutput := ""
Loop, % oAcc.accChildCount
vOutput .= A_Index " " oAcc.accName(A_Index) "`r`n"
Clipboard := vOutput
MsgBox % vOutput

;this doesn't work
oAcc := Acc_Get("Object", "4,22", 0, "ahk_id " hWnd)
vOutput := ""
Loop, % oAcc.accChildCount
vOutput .= A_Index " " oAcc.accName(A_Index) "`r`n"
Clipboard := vOutput
MsgBox % vOutput

Return
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
User avatar
jeeswg
Posts: 5290
Joined: 19 Dec 2016, 01:58
Location: UK

Re: is it possible to write a script that opens specific chrome or firefox tabs

16 Jan 2017, 05:01

OK, well I managed to get it sussed.

Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947

Working script:

autohotkey - Using AHK to activate specific tabs in chrome or firefox - Stack Overflow
http://stackoverflow.com/questions/4147 ... 1#41672931

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, chngrcn, Google [Bot] and 59 guests