Как определить с помощью AppleScript, если что-то играет?

Я пытаюсь добавить эту подпрограмму в свой скрипт, но что-то не так с синтаксисом. Он не принимает «end mySay». Также как я могу определить, воспроизводит ли что-то браузер?

on mySay (p, myMessage)
tell application "QuickTime Player" to set isQTplaying to (playing of documents contains true)
tell application "Music" to set isMusicPlaying to (player state is playing)
tell application "VLC" to set isVLCplaying to playing
--tell application "Brave" to set isiBravePlaying to (player state is playing)
--tell application "FireFox" to set isiFireFoxPlaying to (player state is playing)
--tell application "Safari" to set isiSafariPlaying to (player state is playing)

if isQTplaying or isMusicPlaying or isVLCplaying or isiBravePlaying or isiFireFoxPlaying or isiSafariPlaying then
else
set volume output volume p
say myMessage
set volume output volume myVolumeBefore

end mySay

Ответы (1)

Вы забыли end ifкоманду.

on mySay(p, myMessage)
    tell application "QuickTime Player" to set isQTplaying to (playing of documents contains true)
    tell application "Music" to set isMusicPlaying to (player state is playing)
    tell application "VLC" to set isVLCplaying to playing
    --tell application "Brave" to set isiBravePlaying to (player state is playing)
    --tell application "FireFox" to set isiFireFoxPlaying to (player state is playing)
    --tell application "Safari" to set isiSafariPlaying to (player state is playing)
    if isQTplaying or isMusicPlaying or isVLCplaying or isiBravePlaying or isiFireFoxPlaying or isiSafariPlaying then
    else
        set volume output volume p
        say myMessage
        set volume output volume myVolumeBefore
    end if
end mySay

Я внес некоторые коррективы в ваш код и удалил то, что не смог скомпилировать на своей стороне.

Это что-то большее, чем то, что вы ищете?

on mySay(p, myMessage)
    tell application "QuickTime Player" to set isQTplaying to ¬
        ((documents whose playing is true) is not {}) as boolean
    tell application "Music" to set isMusicPlaying to (player state is playing)
    tell application "VLC" to set isVLCplaying to playing
    if isQTplaying or isMusicPlaying or isVLCplaying then
        set myVolumeBefore to output volume of (get volume settings)
        set volume output volume p
        say myMessage
        set volume output volume myVolumeBefore
    else
        return
    end if
end mySay
🤦‍♂️ есть идеи, как определить, что браузер что-то воспроизводит?
@SteveTorrence проверь мой обновленный ответ
Да так лучше. Буду использовать его, но мне больше всего нужно было обнаружить игру в браузере.
Воспроизведение срабатывает для звуков или потокового аудио или только для видео? Это потрясающие вещи - спасибо!
@bmike Я не знаю о «звуках», но он работает как с аудио, так и с видео.