AppleScript:如何检查哪些应用程序正在播放音频?

AppleScript: how do I check which apps are playing audio?

我是 AppleScript 的新手,我正在尝试编写一个脚本来改变正在播放音频的任何应用程序的音量 [iTunes、Spotify 等]。

AppleScript 有没有办法检查哪些应用程序当前正在播放音频?我已经搜索过这个问题的答案,但一无所获...

更正: 我找到了这个 link http://hypertext.net/2011/11/applescript-powermate-media-apps/

有这个脚本:

    --Define the lastPaused property and give it a default value
    property lastPaused : ""

    --Get current states of iTunes and Spotify
    tell application "iTunes" to set itunesState to (player state as text)
    tell application "Spotify" to set spotifyState to (player state as text)

    --Pause the active app; play the last-paused app
    if itunesState is equal to "playing" then
        tell application "iTunes" to playpause
        set lastPaused to "iTunes"
    else if spotifyState is equal to "playing" then
        tell application "Spotify" to playpause
        set lastPaused to "Spotify"
    else if ((itunesState is equal to "paused") and (lastPaused is equal to "iTunes")) then
        tell application "iTunes" to playpause
    else if ((spotifyState is equal to "paused") and (lastPaused is equal to "Spotify")) then
        tell application "Spotify" to playpause
    end if

所以,这适用于 iTunes/Spotify 但不适用于任何其他播放音频的东西。

applescript 不能只检查哪个应用正在播放音频并停止它[而不必对应用名称进行硬编码吗?]

简答:AppleScript 无法将其作为通用解决方案