$npx -y skills add berabuddies/Semia --skill mcp-applemusicApple Music integration via AppleScript (macOS) or MusicKit API
| 1 | # Apple Music Integration |
| 2 | |
| 3 | Guide for integrating with Apple Music. Covers AppleScript (macOS), MusicKit API (cross-platform), and the critical library-first requirement. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | Invoke when users ask to: |
| 8 | - Manage playlists (create, add/remove tracks, list) |
| 9 | - Control playback (play, pause, skip, volume) |
| 10 | - Search catalog or library |
| 11 | - Add songs to library |
| 12 | - Access listening history or recommendations |
| 13 | |
| 14 | ## Critical Rule: Library-First Workflow |
| 15 | |
| 16 | **You CANNOT add catalog songs directly to playlists.** |
| 17 | |
| 18 | Songs must be in the user's library first: |
| 19 | - ❌ Catalog ID → Playlist (fails) |
| 20 | - ✅ Catalog ID → Library → Playlist (works) |
| 21 | |
| 22 | **Why:** Playlists use library IDs (`i.abc123`), not catalog IDs (`1234567890`). |
| 23 | |
| 24 | This applies to both AppleScript and API approaches. |
| 25 | |
| 26 | ## Platform Comparison |
| 27 | |
| 28 | | Feature | AppleScript (macOS) | MusicKit API | |
| 29 | |---------|:-------------------:|:------------:| |
| 30 | | Setup required | None | Dev account + tokens | |
| 31 | | Playlist management | Full | API-created only | |
| 32 | | Playback control | Full | None | |
| 33 | | Catalog search | No | Yes | |
| 34 | | Library access | Instant | With tokens | |
| 35 | | Cross-platform | No | Yes | |
| 36 | |
| 37 | --- |
| 38 | |
| 39 | # AppleScript (macOS) |
| 40 | |
| 41 | Zero setup. Works immediately with the Music app. |
| 42 | |
| 43 | **Run via Bash:** |
| 44 | ```bash |
| 45 | osascript -e 'tell application "Music" to playpause' |
| 46 | osascript -e 'tell application "Music" to return name of current track' |
| 47 | ``` |
| 48 | |
| 49 | **Multi-line scripts:** |
| 50 | ```bash |
| 51 | osascript <<'EOF' |
| 52 | tell application "Music" |
| 53 | set t to current track |
| 54 | return {name of t, artist of t} |
| 55 | end tell |
| 56 | EOF |
| 57 | ``` |
| 58 | |
| 59 | ## Available Operations |
| 60 | |
| 61 | | Category | Operations | |
| 62 | |----------|------------| |
| 63 | | **Playback** | play, pause, stop, resume, next track, previous track, fast forward, rewind | |
| 64 | | **Player State** | player position, player state, sound volume, mute, shuffle enabled/mode, song repeat | |
| 65 | | **Current Track** | name, artist, album, duration, time, rating, loved, disliked, genre, year, track number | |
| 66 | | **Library** | search, list tracks, get track properties, set ratings | |
| 67 | | **Playlists** | list, create, delete, rename, add tracks, remove tracks, get tracks | |
| 68 | | **AirPlay** | list devices, select device, current device | |
| 69 | |
| 70 | ## Track Properties (Read) |
| 71 | |
| 72 | ```applescript |
| 73 | tell application "Music" |
| 74 | set t to current track |
| 75 | -- Basic info |
| 76 | name of t -- "Hey Jude" |
| 77 | artist of t -- "The Beatles" |
| 78 | album of t -- "1 (Remastered)" |
| 79 | album artist of t -- "The Beatles" |
| 80 | composer of t -- "Lennon-McCartney" |
| 81 | genre of t -- "Rock" |
| 82 | year of t -- 1968 |
| 83 | |
| 84 | -- Timing |
| 85 | duration of t -- 431.0 (seconds) |
| 86 | time of t -- "7:11" (formatted) |
| 87 | start of t -- start time in seconds |
| 88 | finish of t -- end time in seconds |
| 89 | |
| 90 | -- Track info |
| 91 | track number of t -- 21 |
| 92 | track count of t -- 27 |
| 93 | disc number of t -- 1 |
| 94 | disc count of t -- 1 |
| 95 | |
| 96 | -- Ratings |
| 97 | rating of t -- 0-100 (20 per star) |
| 98 | loved of t -- true/false |
| 99 | disliked of t -- true/false |
| 100 | |
| 101 | -- Playback |
| 102 | played count of t -- 42 |
| 103 | played date of t -- date last played |
| 104 | skipped count of t -- 3 |
| 105 | skipped date of t -- date last skipped |
| 106 | |
| 107 | -- IDs |
| 108 | persistent ID of t -- "ABC123DEF456" |
| 109 | database ID of t -- 12345 |
| 110 | end tell |
| 111 | ``` |
| 112 | |
| 113 | ## Track Properties (Writable) |
| 114 | |
| 115 | ```applescript |
| 116 | tell application "Music" |
| 117 | set t to current track |
| 118 | set rating of t to 80 -- 4 stars |
| 119 | set loved of t to true |
| 120 | set disliked of t to false |
| 121 | set name of t to "New Name" -- rename track |
| 122 | set genre of t to "Alternative" |
| 123 | set year of t to 1995 |
| 124 | end tell |
| 125 | ``` |
| 126 | |
| 127 | ## Player State Properties |
| 128 | |
| 129 | ```applescript |
| 130 | tell application "Music" |
| 131 | player state -- stopped, playing, paused, fast forwarding, rewinding |
| 132 | player position -- current position in seconds (read/write) |
| 133 | sound volume -- 0-100 (read/write) |
| 134 | mute -- true/false (read/write) |
| 135 | shuffle enabled -- true/false (read/write) |
| 136 | shuffle mode -- songs, albums, groupings |
| 137 | song repeat -- off, one, all (read/write) |
| 138 | current track -- track object |
| 139 | current playlist -- playlist object |
| 140 | current stream URL -- URL if streaming |
| 141 | end tell |
| 142 | ``` |
| 143 | |
| 144 | ## Playback Commands |
| 145 | |
| 146 | ```applescript |
| 147 | tell application "Music" |
| 148 | -- Play controls |
| 149 | play -- play current selection |
| 150 | pause |
| 151 | stop |
| 152 | resume |
| 153 | playpause -- toggle play/pause |
| 154 | next track |
| 155 | previous track |
| 156 | fast forward |
| 157 | rewind |
| 158 | |
| 159 | -- Play specific content |
| 160 | play (first track of library playlist 1 whose name contains "Hey Jude") |
| 161 | play user playlist "Road Trip" |
| 162 | |
| 163 | -- Settings |
| 164 | set player position to 60 -- seek to 1:00 |
| 165 | set sound volume to 50 -- 0-100 |
| 166 | set mute to true |
| 167 | set shuffle enabled to true |
| 168 | set song repeat to all -- off, one, all |
| 169 | end tell |