2016-05-18 64 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 
相关问题