尋找使用Python從一個Mac應用程序聽distributed notifications幫助/教程/示例代碼聽通知。我知道py-objc lib是python和mac/cocoa類之間的橋樑,Foundation庫可以用來添加觀察者,但需要查找關於如何使用它來監控iTunes的示例或教程。你如何從Mac上的iTunes(使用NSDistributedNotificationCenter)
5
A
回答
11
若有人通過對這個問題,我想通了,怎麼聽,下面的代碼可以工作,但是訪問屬性似乎不像標準python屬性訪問那樣工作。
更新:你不像python ie(.x)那樣訪問屬性,代碼已被更新到下面,現在它生成一個名爲song_details的字典。
向上date3:更新到現在繼承NSObject的代碼,刪除了從類中添加addObserver。將保持代碼更新github,這裏沒有更新的更新。
import Foundation
from AppKit import *
from PyObjCTools import AppHelper
class GetSongs(NSObject):
def getMySongs_(self, song):
song_details = {}
ui = song.userInfo()
for x in ui:
song_details[x] = ui.objectForKey_(x)
print song_details
nc = Foundation.NSDistributedNotificationCenter.defaultCenter()
GetSongs = GetSongs.new()
nc.addObserver_selector_name_object_(GetSongs, 'getMySongs:', 'com.apple.iTunes.playerInfo',None)
NSLog("Listening for new tunes....")
AppHelper.runConsoleEventLoop()
4
GrowlTunes的源代碼可能會爲您提供一些線索。你必須從Objective-C翻譯成PyObjC,但是呃,無論如何。 :)
GrowlTurnesController.m (或者抓取整個咆哮源代碼樹,然後導航到GrowlTunes所以你可以看到這一切在行動:here's a link to the directions on how to get the source
+0
感謝您的幫助,設法使用pyobjc網站和蘋果網站。 – ismail 2009-12-20 20:07:48
相關問題
- 1. NSDistributedNotificationCenter和iTunes
- 2. 使用NSDistributedNotificationCenter獲取iTunes上的歌曲信息更改通知
- 3. 連接的iTunes從iTunes上傳的MAC構建沒有圖標
- 4. 你如何在Mac上
- 5. 如何上傳我的iOS/Mac OSX上的應用程序到iTunes Connect的
- 6. 如何在Mac上使用
- 7. Mac上的iPhone dev迷你
- 8. 如何從Apple iTunes«App Store»和«Mac App Store»
- 9. NSDistributedNotificationCenter通知失敗?
- 10. 你如何定製你的Mac應用程序商店頁面
- 11. 你如何使用Mac OS 10上的終端編寫和編譯C++代碼?
- 12. 在iPhone上使用iTunes
- 13. 將IPA上傳到不同的Mac上的iTunes Connect
- 14. 如何通過在iTunes上
- 15. 如何在mac上使用adb與genymotion?
- 16. 如何在mac os上使用json
- 17. 如何在Mac上使用MAMP標準?
- 18. 如何在Mac OS上使用glGetIntegerv(GL_TEXTURE_BINDING_2D,...)?
- 19. 如何在Mac OS X上使用mpi
- 20. 如何從Itunes獲得應用評價
- 21. 你如何在結構上使用offsetof()?
- 22. 如何使xcode 4.2.1中的iTunes上傳應用程序連接?
- 23. 如何使用sshfs automount從mac到ubuntu
- 24. 你如何從命令行使用greendroid?
- 25. 你如何從Perl使用sed?
- 26. 你如何使用SQL從JCR
- 27. 如何在MAC上使用VBA從Excel 16打開工作簿?
- 28. 如何使用iTunes像滾動條
- 29. 如何使用Applescript搜索iTunes?
- 30. 如何使用iTunes認證類?
的iTunes是否實際上交的分佈式通知,這些天? – 2009-12-19 15:03:49
是的,它確實....在com.apple.iTunes.player下,使用通知表我可以看到它們。 – ismail 2009-12-19 16:26:29