Skip to content

Instantly share code, notes, and snippets.

@junkblocker
Forked from codiez/itunes_notifications.py
Last active August 29, 2015 14:25
Show Gist options
  • Save junkblocker/1b81f4c3c3d81bc7c51b to your computer and use it in GitHub Desktop.
Save junkblocker/1b81f4c3c3d81bc7c51b to your computer and use it in GitHub Desktop.
Listen for distributed notifications from iTunes of the current song
'''
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