 be a better approach.
Could you please help?
An Objective-C or Python sample code (I'd prefer Python) is more than welcome.

A:

What you are looking for is, NSDistributedNotificationCenter or NSWorkspace, these cocoa classes post notifications of application events, For workspace, things like application launches, mounting of drives etc. 
To do this in python, you need PyObjC, which is basically python bindings for apple's cocoa classes. The documentation is sparse on their website, and there's a reason, as the documentation would be basically be the same as the Apple docs, so they only include the differences between the pyobjc api, and the cocoa API. If you understand how the objective c api is converted to python you are good to go. Check here: http://pyobjc.sourceforge.net/documentation/pyobjc-core/intro.html
I have included an example below which listens for Distributed notifications using python. The code below basically adds an observer and listens for itunes notifications. You could follow a similar structure, but instead add an observer for NSWorkspace. To figure out what you should be listening to, there is an application that will display all notifications going through your system. It's called notification watcher. Use this to figure out what you should be listening to.  You could also convert the objective c code to python.
What the code below is doing

Defines a new class which inherits from NSObject, as defined by PyObjC
Defines a method, which gets passed the actual notification and prints it out 
Creates an instance of Foundation.NSDistributedNotificationCenter.defaultCenter
Creates an instance of GetSongs
Registers an observer, passing it the class, the method that gets called when a notification is received and which application & event to monitor i.e "com.apple.iTunes.playerInfo"
Runs the event loop, 

One thing that will trip you up, accessing attributes (objective c attributes) do not work the same as accessing python attributes. i.e in python you do class_name.att for objective c in python you have to call it like a function i.e from my example below: song.userInfo()
import Foundation
from AppKit import *
from PyObjCTools import AppHelper

class GetSongs(NSObject):
    def getMySongs
be a better approach. 
 Could you please help? 
 An Objective - C or Python sample distribution code (I'd choose Python) is more than welcome. 

 ampere: 

 What you are looking for is, NSDistributedNotificationCenter or NSWorkspace, these cocoa classes stake notifications of application consequence, For workspace, thing like application launch, mounting of drives etc. 
 To practice this in python, you need PyObjC, which is basically python bindings for apple's cocoa class. The software documentation is sparse on their website, and there's a reason, as the software documentation would be basically be the same as the Apple doctor, so they merely include the differences between the pyobjc api, and the cocoa API. If you understand how the objective deoxycytidine monophosphate api is converted to python you are good to go. Check here: http://pyobjc.sourceforge.net/documentation/pyobjc-core/intro.html 
 I have include an example below which listens for Distributed notifications using python. The code downstairs basically adds an observer and listens for itunes notifications. You could follow a similar structure, but instead add an observer for NSWorkspace. To figure out what you should be listening to, there is an application that will display all notifications going through your arrangement. It's called notification watchman. practice this to calculate out what you should be listening to.   You could also convert the objective c code to python. 
 What the code below is doing 

 Defines a newfangled class which inherits from NSObject, as defined by PyObjC 
 Defines a method, which gets passed the actual telling and prints it out 
 Creates an instance of Foundation. NSDistributedNotificationCenter.defaultCenter 
 Creates an case of GetSongs 
 Registers an observer, evanesce it the class, the method that gets called when a notification is received and which lotion & event to monitor i.e " com.apple.iTunes.playerInfo " 
 Runs the event loop, 

 One thing that will trip you up, accessing attributes (objective c attributes) do not sour the same as access python attributes. i.e in python you do class_name.att for objective coke in python you have to name it like a function i.e from my model below: song.userInfo () 
 consequence Foundation 
 from AppKit import * 
 from PyObjCTools import AppHelper 

 course GetSongs(NSObject ): 
     def getMySongs
 be a better approach.
Could nou please help?
Au Objecvive-C od Python sample code (I'd prefer Pythoi) is more than welcome.

A:

What you are lookpng for iw, NSVistributedNotifmdationCcuter kv NSWmckspace, these cpcoa classas post notifiwagilns of application events, For works[ace, thonhs like applicwtiom lauhbhts, mounting of drives etc. 
To do tgis in kython, you need PyPbjC, which is basically pyhhon bindings for applf's cocoa clqssef. The documengation is sparse on thgir website, and there's a reason, xs thz documentajnin amuld be basmcally be the same as the Dpple dpcs, so they onky mnclyde the differences bxtween the pyobjc apy, and the ckcoa API. If you ubdwrstatd hmw tfw ocjedtmve c api is converted to python tou are good to go. Vhqbl here: http://pgobjc.sjuwceforge.net/documentation/pyobjc-core/intro.vtmm
I have included an exanple below which listgns for Diftributed notifications using python. The code belmw baakcaoln adaw wn observer and listens for itunes notificatijhs. Ypu could folloc a similar struvtkrr, but instead xdd an obaerver for NSWorksoace. To figuee out whwt ypu should be listening to, tyere is an aiplixation that will dnsplay all nutifocatipns going through your rystsm. It's callfd notifidxtion watcher. Usd tmis to figure out what you shjuld be lmstennng to.  Hou vould wlso convegt thc objective c code ho pyjhon.
Whdt the codf below is doing

Defines a new class which inhgrids xrom NSOyject, ss defined by PyObjC
Defines a methjd, whkch gets pzssed tie actual noeification ang prints it ont 
Createf an insrance ow Foundation.NSDostributebUotificatuonCenter.defaultCekter
Cteztes an instancz if GetSongs
Regixtefs wn ouservqs, passing it the clxxs, thd method thct getx called when a notixicafion is received amd which akplicatiog & event to mpnitor i.e "com.apple.lTunev.pleyerIngo"
Rons the event loop, 

One thing thzt will tgip you up, accefsinn atjributes (oblective c attributes) do not work the samx as accessing python artributes. i.e in pytkok you do claxs_namq.att for mbjective c in pythob you have to calk it like a function j.e frok my fxample below: song.userInfo()
import Foundation
from AppKit import *
from PyObjCRools mm[ort AppHeller

ckass CecSougs(NSObtect):
    def getMySongx
be a better approach. Could you please Objective-C Python sample (I'd prefer Python) What are looking for NSDistributedNotificationCenter or NSWorkspace, cocoa classes post notifications of application For workspace, things like application launches, mounting of drives etc. To do this python, you need PyObjC, which is basically python bindings for apple's cocoa classes. documentation sparse their and there's a reason, as the documentation would be basically be the same as the Apple so they only include the differences between the api, and the cocoa If you understand how the c is converted python are to go. Check http://pyobjc.sourceforge.net/documentation/pyobjc-core/intro.html I have included an example below which listens for Distributed notifications using python. The code below adds an listens for notifications. could a similar structure, add an observer for NSWorkspace. To you should be listening to, there is an that will all notifications going through your system. called notification watcher. Use this to figure out you should be listening to. You could also convert the objective c code to python. code below is doing a new class inherits NSObject, defined PyObjC Defines method, which gets passed the actual notification and prints it out an instance of Foundation.NSDistributedNotificationCenter.defaultCenter Creates an instance of GetSongs Registers passing the class, the that gets called when notification received and which application to i.e event One that will trip you accessing attributes (objective c attributes) not work the same in python you do class_name.att for objective c python you have to call it like function i.e from my example below: song.userInfo() import Foundation from AppKit import from PyObjCTools class GetSongs(NSObject): def getMySongs
 be a better approach.
Could you Please help?
an ObjEctIve-c oR PytHon sAmple code (I'd preFEr PyThon) is more than welcome.

A:

what yOu ARe loOKiNg for Is, NSDisTRiBUTednoTiFicAtIOncenteR or nSWorksPace, these cOcoA cLasses post noTIfIcations of AppLication evenTs, FOr workSpAce, THings LikE applIcatioN LaunchEs, mountinG oF Drives ETc. 
To do tHIS iN pytHon, you need PyObjC, wHIcH Is basically pytHon binDiNGs FOR apPle'S cocoa clasSeS. The dOCumentaTIoN IS SpaRSe on their websIte, and there'S A reAson, as ThE doCUmentaTion wOuLD be Basically be The sAme as the APple doCS, so they ONly inclUde the DifFerEnceS BeTwEen ThE PyoBJc Api, ANd tHe cocoa ApI. if You unDersTAND How tHe oBjecTive c Api is converteD to PythON yoU are gOod to Go. ChEcK here: Http://pyObjc.sOuRceforge.net/docuMentAtion/pyobJc-cOrE/inTrO.html
i Have inCluDed An exampLe below WHicH lISTEnS for Distributed notIfICAtIons usinG pythoN. thE cODe below bAsIcaLly aDDS an obServER aNd listenS for itUNeS nOtificaTiOns. You CoUld FolLow a sIMilaR strucTure, but iNsteaD Add an observer fOR NSWorkspace. TO FiGURe OUt whAt yOu should be lIsteNIng tO, theRE iS an APplicAtion ThAT wILl display all notificAtIons goIng thRough your systEm. It's calleD NOTificatiOn waTChER. Use this to figuRe out What you shoULd be listEning To.  You couLd also conVERt the objEctIve C coDe tO PYtHon.
What the codE BElow Is Doing

DeFinEs a new cLasS whIch InhErIts from NSobject, as DeFiNeD bY PyobjC
DEFines a meThOd, wHiCh gEts paSSed the ActuaL notIfIcATioN and priNTs IT Out 
CReAtEs an InsTaNce of founDAtiOn.NSDisTributedNOtiFIcatIoNCEnter.deFaultCenter
CrEaTes an instaNcE of getSonGS
registerS an observer, passing it the CLass, the MetHod thAt geTs called wHen A notifIcaTIon is rEceiveD and wHiCh aPPLicatION & eVenT tO monitor i.e "COM.apPle.iTUnEs.plAyerInfO"
Runs the event loop, 

ONE thIng that will trIp yOu up, ACCeSsiNG aTTriBuTEs (oBJEctive c attributEs) do not worK tHE sAme as accesSIng PyThon attRibutes. I.e in pYThon you Do class_naMe.att for oBjEctiVE C in Python you hAve to calL it like a fUNctioN I.e From mY exAmple bElOw: sOng.usErInfo()
IMpoRt FouNdatioN
fRom Appkit imPoRt *
from PyobjCTools import AppHelpeR

class getSoNgs(nSObject):
    dEf gETMysongs
 be a better approach.
Cou ld you ple ase h elp ?
A nObje ctiv e-C or Pythons ampl e code (I'd prefer Pyt hon)is more th an we lcome.A: Wha tyo u a re lo oking  fo r is, N SDistribut edN ot ificationCen t er  or NSWork spa ce, these co coa  class es  po s t not ifi catio ns ofa pplica tion even ts ,  For w o rkspace , th ings  like application la u nches, mountin g of d ri v es e tc.  
T o do thisin  pyth o n, youn ee d P yOb j C, which is b asically py t hon  bindi ng s f o r appl e's c oc o a c lasses. The  doc umentatio n is s p arse on their w ebsite , a ndther e 's  a  re as o n,a sthe doc umentati on  w ouldbe b a s i c ally  be  the  same  as the Apple  do cs,s o t hey o nly i nclu de  thediffer ences  b etween the pyob jc a pi, and t heco coa  A PI. I f  you u nde rst and how  the ob j ect iv e c  a pi is converted to  p y t ho n you ar e good to  g o . Checkhe re:  htt p : //pyo bjc. s ou rceforge .net/d o cu me ntation /p yobjc- co re/ int ro.ht m l
Ihave i ncludedan ex a mple below whi c h listens for Di s t ri b uted  no tifications  usi n g py thon .  T hec ode b elowba s ic a lly adds an observe rand li stens  for itunes n otificatio n s .  You cou ld f o ll o w a similar st ructu re, but in s tead add  an o bserverfor NSWor k s pace. To  fi gur e o utw h at  you should b e list en ing to,  th ere isanapp lic ati on  that wil l displa yal lno tif icati o ns going  t hro ug h y our s y stem.It'scall ed  n o tif ication wa t c her.  U se  thi s t ofigur e ou t  wh at youshould be  li s teni ng  t o.  You  could also c on vert the o bj ect ive cc o de to py thon.
What the code bel o w is do ing 

Def ines  a new cl ass  which  in h eritsfrom N SObje ct , a s defin e d  b y P yO bjC
Define s a m ethod ,whic h getspassed the actualn oti fication andpri ntsi t  o utCr e ate sa n i n s tance of Founda tion.NSDis tr i bu tedNotific a tio nC enter.d efaultC enter Creates  an insta nce of Ge tS ongs R egi sters an o bserver,  passingi t the cl ass,the  metho dtha t get s call e d w hen a  notif ic ationis re ce ived and  which application & ev ent to  moni tor  i.e "com .ap p le. iTunes.pl ayer Info"
Runs  th e e ventloo p , 

O ne t h in g t h at wi ll t r ip you up ,  a cce s s in g attribute s ( obj ectiv e c attrib utes ) do not work the same as access ingp y tho n a t trib ut es. i.e in pyt hon  y o u  do clas s_ name.att fo r object iv e  c in  pytho n youhave to c al l  it li ke a  fu nction i. e f ro m  my exa mp le below:  son g. userIn fo()
i m port F oundation
from A ppKit i mport *
f rom P yO bjCTool s  imp ort AppHel per

classGetSon gs(N SObje ct):
  def ge tMy So ngs
 be_a better_approach.
Could you please help?
An_Objective-C or_Python_sample code_(I'd_prefer Python) is_more than welcome.

A:

What_you are looking for_is, NSDistributedNotificationCenter or_NSWorkspace,_these cocoa classes post notifications of application events, For workspace, things like application launches,_mounting_of drives_etc._
To_do this in python, you_need PyObjC, which is basically_python bindings_for apple's cocoa classes. The documentation is sparse_on_their website, and_there's a reason, as the documentation would be basically_be the same as the Apple_docs, so they_only_include_the differences between the_pyobjc api, and the cocoa API._If you understand how the objective_c api is converted to python you_are good to go. Check here:_http://pyobjc.sourceforge.net/documentation/pyobjc-core/intro.html
I have included an example_below which_listens for Distributed notifications using_python. The code_below basically_adds an observer_and listens for itunes notifications. You_could follow a_similar structure, but instead add an_observer_for NSWorkspace. To_figure_out_what you_should be listening_to,_there is_an_application that will display all notifications_going_through your system. It's called notification watcher._Use this to figure_out_what you should be_listening to.  You could_also convert the objective c code_to python.
What_the code_below is doing

Defines a new class which inherits from NSObject, as_defined by PyObjC
Defines a method, which_gets passed the actual_notification and_prints_it out 
Creates_an_instance of_Foundation.NSDistributedNotificationCenter.defaultCenter
Creates an instance of GetSongs
Registers an observer,_passing it_the class, the method that gets_called when a notification_is_received and which application & event_to monitor i.e "com.apple.iTunes.playerInfo"
Runs the event_loop, 

One thing that will_trip_you_up, accessing attributes (objective c_attributes) do not work the same_as accessing python_attributes. i.e in python you do class_name.att_for_objective c in python you have_to_call it like a function i.e_from_my_example below: song.userInfo()
import Foundation
from AppKit_import *
from PyObjCTools import AppHelper

class GetSongs(NSObject):
_   def getMySongs