2016-05-18 62 views
0

我試圖訪問有關Mac應用程序當前狀態的信息,就像我在Linux上使用dbus一樣。從App.sdef獲取當前應用程序信息

我試圖做的這個應用程序是Spotify。我搜索了包內容,發現/ Resources目錄中有一個Spotify.sdef文件。我對這些「腳本定義」做了一些研究,我認爲有一種方法可以訪問Spotify.sdef文件中描述的數據(即標題和藝術家信息)。我可能完全錯誤,因爲我對Cocoa開發沒有任何經驗。

如果有人能夠指引我訪問我認爲可以從應用程序包內容中的「腳本定義」文件訪問的數據,我將不勝感激。我的最終目標是能夠通過簡單的終端命令查看Spotify當前播放的歌曲。

回答

1

你見過Spotify's AppleScript docs?這個例子的小修改應該做你正在尋找的東西:

#!/usr/bin/env osascript 

set currentlyPlayingTrack to getCurrentlyPlayingTrack() 
log currentlyPlayingTrack 

on getCurrentlyPlayingTrack() 
    tell application "Spotify" 
     set currentArtist to artist of current track as string 
     set currentTrack to name of current track as string 
     return currentArtist & " - " & currentTrack 
    end tell 
end getCurrentlyPlayingTrack 
相關問題