Created
April 29, 2016 09:43
-
-
Save loretoparisi/6092634d34e97a062029b078215b6bdc to your computer and use it in GitHub Desktop.
Listen Spotify MacOS notifications via Cocoa NSDistributedNotificationCenter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Listen Spotify MacOS App for Notifications | |
It currently supports | |
`com.spotify.client.PlaybackStateChanged` | |
@author: loretoparisi at gmail dot com | |
''' | |
import Foundation | |
import json | |
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())) | |
json_str = json.dumps(song_details, indent=4, sort_keys=False) | |
print json_str | |
nc = Foundation.NSDistributedNotificationCenter.defaultCenter() | |
GetSongs = GetSongs.new() | |
nc.addObserver_selector_name_object_(GetSongs, 'getMySongs:', 'com.spotify.client.PlaybackStateChanged',None) | |
NSLog("Listening for Spotify PlaybackStateChanged....") | |
AppHelper.runConsoleEventLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Response format:
How to run: