Skip to content

Creating an Apple Music plugin using MusicKit #3053

@lgarron

Description

@lgarron

iTunes is long defunct, and so is its API: #2495

The official way to interact with the music library on macOS is MusicKit: https://developer.apple.com/documentation/applemusicapi/

I have the absolute barest version of a plugin at https://github.com/lgarron/AppleMusic-qsplugin

It:

  • Indexes all songs in the library and places them in the catalog.
  • Has a "Play" action that can be used to play a song.

Image

Image

This works!

However, it does nothing else useful and still contains boilerplate. In addition:

  • This requires adding NSAppleMusicUsageDescription to Info.plist in Quicksilver itself:
    <key>NSAppleEventsUsageDescription</key>
    <string>Quicksilver requires this access to run certain actions and update your catalog.</string>
    <key>NSAppleScriptEnabled</key>
    <true/>
    <key>NSCalendarsUsageDescription</key>
    <string>Create events directly from Quicksilver (only used when the &apos;Calendar&apos; plugin is enabled)</string>
    <key>NSContactsUsageDescription</key>
    <string>View, copy and paste information from your contacts in Quicksilver (only used when the &apos;Contacts&apos; plugin is enabled)</string>
    <key>NSRemindersUsageDescription</key>
    <string>Create reminders directly from Quicksilver (only used when the &apos;Calendar&apos; plugin is enabled)</string>
    . This is probably simple.
  • Building with the MusicKit API requires targeting macOS 14 or above. I do not know if it's possible to build the plugin like this without also increasing the target for Quicksilver itself.
  • The MusicKit API is asynchronous, and interfaces inside Quicksilver are not. I was able to hack around this using a very unadvisable workaround to make synchronous code block on a Task: https://forums.swift.org/t/using-async-functions-from-synchronous-functions-and-breaking-all-the-rules/59782/4
    • Given that it takes several seconds to index a music library, it is probably a good idea to have an async API for indexing. But I think that's a much larger architectural change. I don't know the best compromise.
  • The song (queue) stops playing when Quicksilver exits. It seems this may be a limitation of the MusicKit API. Given Quicksilver's propensity for crashing I'd really like a workaround, but it seems the only other one is effectively to use AppleScript.

Anyhow, I don't know how much time I can dedicate to this but hopefully my repo shows that it's at least possible to rebuild the functionality of the old iTunes plugin from scratch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions