Skip to content

Instantly share code, notes, and snippets.

@DomiR
Forked from codiez/itunes_notifications.py
Created May 16, 2013 22:58
Show Gist options
  • Save DomiR/5595755 to your computer and use it in GitHub Desktop.
Save DomiR/5595755 to your computer and use it in GitHub Desktop.
'''
This python script listens for distributed notifications from iTunes of new songs playing,
works alot better then constantly polling.
'''
import Foundation
from AppKit import *
from PyObjCTools import AppHelper
class GetSongs(NSObject):
def getMySongs_(self, song):
song_details = {}
ui = song.userInfo()
song_details = dict(zip(ui.keys(), ui.values()))
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment