2013-11-15 53 views
0

我想做一個腳本,需要檢查是否有AirPlay設備連接並正在使用。
我嘗試過在很多地方搜索,但我似乎無法找到任何文檔,有沒有人有任何想法我會這樣做?
爲了進一步澄清,我想一個腳本,是沿着線的東西:我如何檢查是否有Airplay設備連接

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 

編輯:澄清,我需要什麼添加的應用找出

+0

更新我的回答 – markhunte

回答

0

嗯。

但沒有鍛鍊如何從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 

UPDATE *

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設備

+0

感謝您的這一點,雖然這不是我正在尋找的,我可能沒有正確地說出來,我應該可以解釋我有什麼很遠,當我點擊一個特定的按鍵時,它會運行一個程序,將iTunes中的聲音淡出,然後再次返回,然後再次開始播放,我想要的是當連接到播放時有更大的延遲消失,因爲那裏總是一個連接延遲,否定淡入。 – AlexGadd

+0

你可以編輯你的問題,並添加此信息和任何其他有助於解釋你想要的信息。包括該應用程序。 – markhunte