【问题标题】:How do i check if there is an Airplay device connected如何检查是否连接了 Airplay 设备
【发布时间】:2013-11-15 15:54:12
【问题描述】:

我想做一个脚本来检查是否有连接并正在使用的播放设备。
我试过在很多地方搜索,但我似乎找不到任何关于此的文档,有人知道我会怎么做吗?
为了进一步澄清,我想要一个类似于以下内容的脚本:

 if airplay device is in use then //(pause for longer)
 else //(the script that is already there)

这是我当前的代码

global okflag
set okflag to false
set front_app to (path to frontmost application as Unicode text)

-- check if iTunes is running 
tell application "System Events"
    if process "iTunes" exists then
        set okflag to true --iTunes is running
    end if
end tell

if okflag is true then
    set CV to output volume of (get volume settings)

tell application "iTunes"
    if (player state is playing) then
        set currentVolume to the sound volume
        set Timer to ""
        display dialog "Sleep Time (Minutes)" with title "iTunes Timer" default answer Timer buttons {"Cancel", "OK"} default button 2
        set Timer to text returned of the result
        set the_button to button returned of (display dialog "Shutdown after countdown?" with title "iTunes Timer" buttons {"No", "Yes"} default button 2)
        delay Timer * 60
        repeat with i from currentVolume to 0 by -1
            set the sound volume to i
            delay 0.6
        end repeat
        pause
        set player position to (player position - 60)
        --Restore original volume
        set the sound volume to currentVolume
        if the_button is "Yes" then tell application "System Events"
            shut down
        end tell
    else
        display dialog "Nothing Playing" with title "iTunes Timer" giving up after 2
    end if


end tell

else
display dialog "iTunes is not running" with title "iTunes Timer" giving up after 2

end if

编辑:添加应用程序以澄清我需要找出的内容

【问题讨论】:

    标签: macos applescript itunes osx-mavericks


    【解决方案1】:

    嗯。

    但是,如果您从 iTunes 流式传输,则没有讨论如何获得状态。 (到目前为止)

    但是,如果 Airplay 被用作扩展桌面空间或镜像,那么它是否会在系统配置文件中用于显示。 SPDisplaysDataType

    这个applescript至少说明了这一点。

          set connected to ""
    try
        set connected to do shell script "system_profiler  SPDisplaysDataType | grep -i \"AirPlay\" "
        if connected contains "Connection Type: AirPlay" then
            set connected to "Connected as a Display or mirroring"
        end if
    on error err
        log err
        if err contains "The command exited with a non-zero status" then
            --do somthing
            set connected to "Not connected as a Display or mirroring"
        end if
    end try
    connected
    

    更新*

    iTunes 命令现在有一些播放命令。不知道他们什么时候出现。 但是一个使用示例:

        tell application "iTunes"
            set isPlaying to player state
    
    
        if isPlaying is playing then
                log isPlaying
                set airPlayEnabled to AirPlay enabled
                if airPlayEnabled then
    
                      log airPlayEnabled
    
                else
    
                    airPlayEnabled
        end if
    
    
            else
    
                log isPlaying
            end if
    
        end tell
    

    AirPlay 启用 AFAIK 仅适用于运行它的 iTunes 播放器。并且不适用于可能占用 Airplay 设备的任何其他设备

    【讨论】:

    • 谢谢你,虽然这不是我想要的,我可能没有正确用词,我应该解释一下我到目前为止所拥有的,当我按下一个特定的键时,它会运行程序将 iTunes 上的声音淡出,然后再重新进入并再次开始播放,我想要它做的是在连接到 airplay 时有更大的淡入延迟,因为总是有一个连接延迟可以抵消淡入。
    • 您能否编辑您的问题并添加此信息以及任何其他有助于解释您想要什么的信息。包括上述应用。
    猜你喜欢
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多