He olvidado cómo encontrar una pestaña por su nombre y devolver el valor (p. ej., pestaña 2) y, finalmente, establecer la pestaña como pestaña activa también.
He intentado lo siguiente, pero no funciona:
set titleString to "
"
tell application "Google Chrome"
set window_list to every window # get the windows
repeat with the_window in window_list # for every window
set tab_list to every tab in the_window # get the tabs
repeat with the_tab in tab_list # for every tab
set the_title to the title of the_tab # grab the title
if the_tab contains (Name to search" as text) then
display notification "the_tab"
end if
return # concatenate
end repeat
end repeat
end tell
También traté de comenzar algo con JavaScript:
tell application "Google Chrome"
set window_list to every window
repeat with the_window in window_list
set tab_list to every tab in the_window
tell tab_list to set TheTab to execute javascript "document.title"
end repeat
end tell
Pero luego obtengo:
{«class CrTb» id 4 de la ventana id 1 de la aplicación "Google Chrome", «class CrTb» id 9 de la ventana id 1 de la aplicación "Google Chrome", «class CrTb» id 2 de la ventana id 1 de la aplicación "Google Chrome ", «class CrTb» id 189 de la ventana id 1 de la aplicación "Google Chrome"} no entiende el mensaje "ejecutar".
¿Cómo puedo proceder?
Al no estar seguro del alcance total de lo que está tratando de lograr, el siguiente código puede ser más de lo que necesita. Sin embargo, permite buscar el nombre de la pestaña y luego establece la pestaña que contiene la cadena de búsqueda como active tab
.
El siguiente código es una reelaboración del código presentado en Buscar pestañas de Safari con AppleScript . Hubiera sido bueno haber podido cambiar tell application "Safari"
y tell application "Google Chrome"
el script funcionara, pero debido a las diferencias en las propiedades de una pestaña entre las dos aplicaciones, es por eso que no funcionaría.
Lo que hace este script :
active tab index
, lo que significa que la pestaña ahora es la pestaña actual. Si hay más de una ventana, la ventana que contiene esa pestaña se coloca al frente de todas las demás ventanas de Google Chrome.active tab index
, lo que significa que la pestaña ahora es la pestaña actual. Si hay más de una ventana, la ventana que contiene esa pestaña se coloca al frente de todas las demás ventanas de Google Chrome.set searchString to text returned of (display dialog "Enter a string to search for:" default answer "" with title "Find Google Chrome Tab")
tell application "Google Chrome"
set win_List to every window
set win_MatchList to {}
set tab_MatchList to {}
set tab_NameMatchList to {}
repeat with win in win_List
set tab_list to every tab of win
repeat with t in tab_list
if searchString is in (title of t as string) then
set end of win_MatchList to win
set end of tab_MatchList to t
set end of tab_NameMatchList to (id of win as string) & ". " & (title of t as string)
end if
end repeat
end repeat
if (count of tab_MatchList) is equal to 1 then
set w to item 1 of win_MatchList
set index of w to 1
my setActiveTabIndex(t, searchString)
else if (count of tab_MatchList) is equal to 0 then
display dialog "No match was found!" buttons {"OK"} default button 1
else
set which_Tab to choose from list of tab_NameMatchList with prompt "The following Tabs matched, please select one:"
if which_Tab is not equal to false then
set oldDelims to (get AppleScript's text item delimiters)
set AppleScript's text item delimiters to "."
set tmp to text items of (which_Tab as string)
set w to (item 1 of tmp) as integer
set AppleScript's text item delimiters to oldDelims
set index of window id w to 1
my setActiveTabIndex(t, searchString)
end if
end if
end tell
on setActiveTabIndex(t, searchString)
tell application "Google Chrome"
set i to 0
repeat with t in tabs of front window
set i to i + 1
if title of t contains searchString then
set active tab index of front window to i
return
end if
end repeat
end tell
end setActiveTabIndex
La pregunta tiene tres años, pero supongo que otros pueden encontrar su camino aquí, como lo hice yo, por lo que mi respuesta aquí está dirigida a usted, la persona que actualmente está considerando cómo hacer esto:
¿Su objetivo es hacer esto manualmente o mediante programación? ¿Necesita una solución de código para insertar en alguna automatización que está creando, o es su primera suposición de cómo lograr su objetivo de interfaz de usuario de poder encontrar la pestaña que desea mientras trabaja de forma interactiva?
Si es más tarde, si solo necesita encontrar una pestaña de 54 repartidas entre 11 ventanas en 7 espacios de escritorio, entonces le recomiendo la extensión de Chrome "Pestañas".https://chrome.google.com/webstore/detail/tabs/cdbepibloojgbmnofbejfgglmdlifadj
La fuente de esta extensión gratuita está en GitHub. Cuando hace clic en el ícono en Chrome, se abre una ventana emergente que enumera todas las pestañas abiertas por ventana y se enfoca en un campo de búsqueda para que pueda escribir una cadena de búsqueda de inmediato. A medida que escribe, los resultados se reducen. Cuando vea el nombre de la pestaña que está buscando, haga clic en él e inmediatamente irá a él, en cualquier espacio de escritorio y ventana que sea.
Uso "Tabs" varias veces al día.
usuario3439894
AppleScript's text item delimiters
tener en cuenta su estado anterior y restablecerlo después de haberlo cambiado para obtener lowindow id
que se devuelve dellist
cuadro de diálogo . En este caso particular, solo usando este código en un script dado, realmente no habría importado. Sin embargo, se considera una mejor práctica de programación hacerlo al modificar una configuración predeterminada.Kevin