How to get all the text of chrome live caption and always use applescript to translate it into other languages and output it to another window. The following is part of the code that can only print out the text.
Here I am traversing all static controls and getting their values to form a string variable.
set endTime to (current date) + 10
repeat
try
#log "echo 1"
tell application "System Events"
#log "echo 2"
if exists process "Google Chrome" then
#log "echo 3"
tell process "Google Chrome"
#log "echo 4"
tell window "Live Caption"
#log "echo 5"
set uiElements to entire contents
set uiElem3 to item -3 of uiElements
set allTexts to ""
repeat with uiElem in uiElements
try
#log "echo 6"
if class of uiElem as string = "static text" then
#log "echo 7"
set res to value of uiElem as string
if res does not contain "Live Caption is not available at the moment" then
#log "echo 8" #log res
set allTexts to (allTexts & res) & ""
end if
else
#log "不是static text类型"
end if
on error errMsg number errNum
end try
end repeat
#log "echo 9"
#log (name of uiElem3) & ""
#set allTexts to (allTexts & name of uiElem3) & ""
#log "echo 10"
log allTexts
set allTexts to ""
log "*************************************************"
delay 0.5
end tell
end tell
end if
end tell
on error errMsg number errNum
if (current date) > endTime then
exit repeat
end if
end try
end repeat