No sé cómo adaptar este script, que resalta el texto en Safari, para que funcione con Google Chrome:
set myList to {"AppleScript", "2018", "demo@apple.com"}
tell application "Safari"
'window.find()' command change the scroll position when it select the founded string
set scrollPos to do JavaScript "document.designMode = 'on'; [window.pageXOffset.toString(),window.pageYOffset.toString()]" in document 1
repeat with thisText in myList
do JavaScript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()" in document 1
end repeat
-- restore the scroll position
do JavaScript "document.designMode = 'off'; window.scrollTo(" & (item 1 of scrollPos) & ", " & (item 2 of scrollPos) & ")" in document 1
end tell
Aquí está mi versión de Google Chrome:
set myList to {"AppleScript", "2018", "CLOSED"}
tell application "Google Chrome"
tell tab 3 of window 1 to set scrollPos to execute javascript "document.designMode = 'on'; [window.pageXOffset.toString(),window.pageYOffset.toString()]"
repeat with thisText in myList
execute javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
end repeat
execute javascript "document.designMode = 'off'; window.scrollTo(" & (item 1 of scrollPos) & ", " & (item 2 of scrollPos) & ")"
end tell
Responder :
tell application "Google Chrome"
execute tab 3 of window 1 javascript "document.designMode = 'on'; [window.pageXOffset.toString(),window.pageYOffset.toString()]"
--> {"0", "0"}
execute current application javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('AppleScript', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
--> missing value
execute current application javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('2018', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
--> missing value
execute current application javascript "var sel = window.getSelection();\n sel.collapse(document.body, 0);//------ To start at the beginning of the document, not after the selectioned text\n while (window.find('CLOSED', true)) {document.execCommand('HiliteColor', false, '#5cdf64');}\n sel.collapseToEnd()"
--> missing value
execute current application javascript "document.designMode = 'off'; window.scrollTo(0, 0)"
--> missing value
end tell
Result:
missing value
Asegúrate de haber habilitado JavaScript de AppleScript en Google Chrome
La ejecución de JavaScript a través de AppleScript está desactivada. Para activarlo, desde la barra de menús, vaya a Ver > Desarrollador > Permitir JavaScript de Apple Events.
He realizado algunos cambios en su secuencia de comandos para que funcione, con los cambios resaltados en negrita.
tell window 1
, no solo un verbo. He agregado to tell window 1
a la información adjunta de la aplicación.establecer myList en {"AppleScript", "2018", "CERRADO"} dígale a la aplicación "Google Chrome" que le diga a la ventana 1 que ejecute la pestaña activa javascript "document.designMode = 'on';" -- scrollPos y desplazamiento de página eliminados repetir con este texto en mi lista ejecutar javascript de pestaña activa "var sel = window.getSelection(); sel.collapse(documento.cuerpo, 0); while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');} sel.collapseToEnd()" terminar repetir ejecutar la pestaña activa javascript "document.designMode = 'off';" -- scrollPos y desplazamiento de página eliminados
Para ejecutarlo en todas las pestañas, envuélvalo con repeat with atab in tabs
:
Dile a la aplicación "Google Chrome" que le diga a la ventana 1 que repita con atab en las pestañas. Ejecuta atab javascript "document.designMode = 'on';" -- scrollPos y desplazamiento de página eliminados repetir con este texto en mi lista ejecutar atab javascript "var sel = window.getSelection(); sel.collapse(documento.cuerpo, 0); while (window.find('" & thisText & "', true)) {document.execCommand('HiliteColor', false, '#5cdf64');} sel.collapseToEnd()" terminar repetir ejecutar atab javascript "document.designMode = 'off';" -- scrollPos y desplazamiento de página eliminados end repeat end tell
repeat with atab in tabs
, ver editar
grg
'window.find()' command
línea. ¿Esa línea estaba destinada a ser un comentario? ¿De dónde sacaste ese guión?base de datos
Kevin