ITunes Plugin Programming: Event Interceptors

Are there any good solutions to capture events from iTunes?

I would like to create a plugin that is inside iTunes and responds to rating changes for certain songs. For Windows, they have an SDK that I haven't studied yet, but I would also like to find something for the Mac.

Any suggestions?

+3
source share
2 answers

As far as I know, Apple provides a free (as at zero cost) SDK for iTunesVisual Plug-Ins for OS X and Windows. If you cannot get what you need, you can always use the iTunes Apple Events scripting interface to monitor through polling from another OS X application using an OSA-compatible interface such as AppleScript or appscript with Python, Ruby or Objective-C. This may not be what you would like, but it is documented and maintained.

For example, with py-appscript, here is how to access the current track and those that were in the recently played smartlist:

>>> from appscript import *
>>> it = app('iTunes')
>>> it.current_track.rating()  # 40 == 2 stars
40
>>> len(it.playlists['Recently Played'].tracks())
80
>>> it.playlists['Recently Played'].tracks[1].rating()
40
>>> it.playlists['Recently Played'].tracks[1].rating.set(to=100)
>>> it.playlists['Recently Played'].tracks[1].rating()  # 100 = 5 stars
100

You can also filter various metadata fields (open the iTunes.app script definition in the AppleScript Script editor to view):

>>> import datetime
>>> an_hour_ago = datetime.datetime.now() - datetime.timedelta(hours=1)
>>> it.playlists['Library'].tracks[its.modification_date >= an_hour_ago]()
[app(u'/Applications/iTunes.app').sources.ID(45).library_playlists.ID(49347).file_tracks.ID(72017)]

, .

+2

Mac iTunes . , . , iTunes , :

  • , , iTunes,

  • , PreFab UI Actions, iTunes AppleScripts

  • , FSEvent iTunes Music Library.xml, iTunes . , iTunes , , , , .

, , , Mac, , , , .

0

Source: https://habr.com/ru/post/1722960/


All Articles