Tengo un AppleScript que busca la pestaña y ejecuta un JS en la pestaña seleccionada, Es el trabajo debido a este :
set current tab of w to t
set index of w to 1
pero me gustaría mejorar el código para poder referenciar la pestaña, por el momento como puedes ver sólo estoy refiriendo el ID de la ventana y está bien cuando sé el número de la pestaña pero ¿como puedo referirme también a la pestaña?
do JavaScript "document.getElementsByClassName('myJShere')[0].click();" in tab tab 1 of window id theWindowID
He intentado establecer theTabNumber como (id de t como cadena) pero eso no funciona
t en mi ejemplo actual, devuelve el elemento 3 de {pestaña 1 de la ventana id 6615 de la aplicación "Safari", pestaña 2 de la ventana id 6615 de la aplicación "Safari", pestaña 3 de la ventana id 6615 de la aplicación "Safari", pestaña 4 de la ventana id 6615 de la aplicación "Safari"}
Lo he intentado:
set theTabNumber to item 1 of t
return theTabNumber
pero esta vuelta
tab 3 of window id 6615 of application "Safari"
Supongo que podría utilizar la delimitación de texto, pero eso no parece correcto
full script
set theTABID to 0
set searchpat to "Facebook"
tell application "Safari"
set winlist to every window
set winmatchlist to {}
set tabmatchlist to {}
set tabnamematchlist to {}
repeat with win in winlist
set ok to true
try
set tablist to every tab of win
on error errmsg
--display dialog name of win as string
set ok to false
end try
if ok then
repeat with t in tablist
if searchpat is in (name of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & 1 & ". " & (name of t as string)
set theTABID to (id of win as string)
##return (index of t as string)
--display dialog name of t as string
else if searchpat is in (URL of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & 1 & ". " & (URL of t as string)
--display dialog name of t as string
end if
end repeat
end if
end repeat
set w to item 1 of winmatchlist
set t to item 1 of tabmatchlist
set current tab of w to t
set index of w to 1
end tell
if theTABID = 0 then
set searchpat to "Twitter"
##set searchpat to "Case Management"
tell application "Safari"
set winlist to every window
set winmatchlist to {}
set tabmatchlist to {}
set tabnamematchlist to {}
repeat with win in winlist
set ok to true
try
set tablist to every tab of win
on error errmsg
--display dialog name of win as string
set ok to false
end try
if ok then
repeat with t in tablist
if searchpat is in (name of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & 1 & ". " & (name of t as string)
set theTABID to (id of win as string)
##return (index of t as string)
--display dialog name of t as string
else if searchpat is in (URL of t as string) then
set end of winmatchlist to win
set end of tabmatchlist to t
set end of tabnamematchlist to (id of win as string) & "." & 1 & ". " & (URL of t as string)
--display dialog name of t as string
end if
end repeat
end if
end repeat
set w to item 1 of winmatchlist
set t to item 1 of tabmatchlist
set current tab of w to t
set index of w to 1
end tell
end if
tell application "Safari"
do JavaScript "document.getElementsByClassName('a8c37x1j ni8dbmo4 stjgntxs l9j0dhe7 ltmttdrg g0qnabr5 ')[0].click();" in current tab of window id theTABID
end tell