Default voice command: “Previous window” does not work in Tahoe 26.6.2

Hello.

The default voice commands ‘Previous window’ and ‘Next window’ do not work on my Tahoe 26.6.2.

The solution I’ve found for the various applications works correctly, but the algorithm is slow, and I’d like to share it in the hope of finding a more satisfactory alternative.

In this case, I’m only presenting the code for ‘Previous window’

Previous window:


tell application "System Events"
	set nombreApp to name of (first application process whose frontmost is true)
end tell

if nombreApp is "Finder" then
	------------------------------------------------------------
	-- FINDER (MRU real)
	------------------------------------------------------------
	tell application "Finder"
		set listaVentanas to every window
		set numVentanas to count of listaVentanas
		if numVentanas > 1 then
			set ventanaObjetivo to item numVentanas of listaVentanas
			if collapsed of ventanaObjetivo then
				set collapsed of ventanaObjetivo to false
			end if
			activate
			set index of ventanaObjetivo to 1
		else -- Com. Pers. → AÑADIDO
			my imposible(nombreApp, numVentanas)
		end if
	end tell
	
else if nombreApp is "Google Chrome" then
	------------------------------------------------------------
	-- CHROME (MRU real)
	------------------------------------------------------------
	tell application "Google Chrome"
		set listaVentanas to every window
		set numVentanas to count of listaVentanas
		if numVentanas > 1 then
			set ventanaObjetivo to item numVentanas of listaVentanas
			if minimized of ventanaObjetivo then
				set minimized of ventanaObjetivo to false
			end if
			activate
			set index of ventanaObjetivo to 1
		else -- Com. Pers. → AÑADIDO
			my imposible(nombreApp, numVentanas)
			
		end if
	end tell
	
else if nombreApp is "Microsoft Excel" then
	------------------------------------------------------------
	-- EXCEL (MRU real; sin id ni index utilizables, activación vía System Events)
	------------------------------------------------------------
	set numVentanas to 0
	set nombreObjetivo to ""
	
	tell application "Microsoft Excel"
		set listaVentanas to every window
		set numVentanas to count of listaVentanas
		if numVentanas > 1 then
			set nombreObjetivo to name of item numVentanas of listaVentanas
			activate
			if collapsed of window nombreObjetivo then
				set collapsed of window nombreObjetivo to false
			end if
		else -- Com. Pers. → AÑADIDO
			my imposible(nombreApp, numVentanas)
			
		end if
	end tell
	
	if numVentanas > 1 then
		tell application "System Events"
			perform action "AXRaise" of window nombreObjetivo of process "Microsoft Excel"
		end tell
	end if
	
else if nombreApp is "Microsoft Word" then
	------------------------------------------------------------
	-- WORD (sin MRU real; every window no se reordena con el uso,
	-- ni tiene atajo nativo de "ventana anterior/siguiente" propio;
	-- orden alfabético fijo + frontmost vía System Events)
	------------------------------------------------------------
	set numVentanas to 0
	set nombreObjetivo to ""
	
	tell application "Microsoft Word"
		set listaVentanas to every window
		set numVentanas to count of listaVentanas
		if numVentanas > 1 then
			set nombresOrdenados to {}
			repeat with w in listaVentanas
				set end of nombresOrdenados to name of w
			end repeat
			repeat with i from 2 to count of nombresOrdenados
				set valorActual to item i of nombresOrdenados
				set j to i - 1
				repeat while j > 0 and item j of nombresOrdenados > valorActual
					set item (j + 1) of nombresOrdenados to item j of nombresOrdenados
					set j to j - 1
				end repeat
				set item (j + 1) of nombresOrdenados to valorActual
			end repeat
			
			tell application "System Events"
				set nombreFrente to name of window 1 of process "Microsoft Word"
			end tell
			
			set posicionFrente to 0
			repeat with i from 1 to count of nombresOrdenados
				if item i of nombresOrdenados is nombreFrente then
					set posicionFrente to i
					exit repeat
				end if
			end repeat
			
			if posicionFrente is 1 then
				set posicionAnterior to numVentanas
			else
				set posicionAnterior to posicionFrente - 1
			end if
			
			set nombreObjetivo to item posicionAnterior of nombresOrdenados
			
			activate
			if collapsed of window nombreObjetivo then
				set collapsed of window nombreObjetivo to false
			end if
		else -- Com. Pers. → AÑADIDO
			my imposible(nombreApp, numVentanas)
			
		end if
	end tell
	
	if numVentanas > 1 then
		tell application "System Events"
			perform action "AXRaise" of window nombreObjetivo of process "Microsoft Word"
		end tell
	end if
	
else
	------------------------------------------------------------
	-- CUALQUIER OTRA APP (MRU real; validada en TextEdit, Vista Previa
	-- y Editor de Scripts; filtra ventanas fantasma sin nombre)
	------------------------------------------------------------
	try
		tell application nombreApp
			set listaVentanasTodas to every window
			set listaVentanas to {}
			repeat with w in listaVentanasTodas
				try
					if (name of w) is not "" and (visible of w) then
						set end of listaVentanas to w
					end if
				end try
			end repeat
			
			set numVentanas to count of listaVentanas
			if numVentanas > 1 then
				set ventanaObjetivo to item numVentanas of listaVentanas
				activate
				try
					if miniaturized of ventanaObjetivo then
						set miniaturized of ventanaObjetivo to false
					end if
				end try
				set index of ventanaObjetivo to 1
			end if
		end tell
	end try
end if

-- Com. Pers. → AÑADIDO
on imposible(nombreApp, numVentanas)
	if numVentanas = 1 then
		display dialog nombreApp & " solo tiene esta ventana" giving up after 2
	else --if numVentanas = 0 then
		display dialog nombreApp & " no tiene ventanas abiertas" giving up after 2
	end if
end imposible


I would be grateful for any help you can offer, and thank you in advance.