本文へ移動
cccskills
無料GitHub で公開

apple-music-2

Apple Music integration via AppleScript (macOS) or MusicKit API

日本語の概要は準備中です。原文の説明を表示しています。

sundial-org/awesome-openclaw-skillsスター 671(GitHub 671 + cccskills 0)

実行スコア 未検証

インストール方法を見る

含まれるファイル(1)

  • SKILL.md15.9 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Apple Music Integration

Guide for integrating with Apple Music. Covers AppleScript (macOS), MusicKit API (cross-platform), and the critical library-first requirement.

When to Use

Invoke when users ask to:

  • Manage playlists (create, add/remove tracks, list)
  • Control playback (play, pause, skip, volume)
  • Search catalog or library
  • Add songs to library
  • Access listening history or recommendations

Critical Rule: Library-First Workflow

You CANNOT add catalog songs directly to playlists.

Songs must be in the user's library first:

  • ❌ Catalog ID → Playlist (fails)
  • ✅ Catalog ID → Library → Playlist (works)

Why: Playlists use library IDs (i.abc123), not catalog IDs (1234567890).

This applies to both AppleScript and API approaches.

Platform Comparison

FeatureAppleScript (macOS)MusicKit API
Setup requiredNoneDev account + tokens
Playlist managementFullAPI-created only
Playback controlFullNone
Catalog searchNoYes
Library accessInstantWith tokens
Cross-platformNoYes

AppleScript (macOS)

Zero setup. Works immediately with the Music app.

Run via Bash:

osascript -e 'tell application "Music" to playpause'
osascript -e 'tell application "Music" to return name of current track'

Multi-line scripts:

osascript <<'EOF'
tell application "Music"
    set t to current track
    return {name of t, artist of t}
end tell
EOF

Available Operations

CategoryOperations
Playbackplay, pause, stop, resume, next track, previous track, fast forward, rewind
Player Stateplayer position, player state, sound volume, mute, shuffle enabled/mode, song repeat
Current Trackname, artist, album, duration, time, rating, loved, disliked, genre, year, track number
Librarysearch, list tracks, get track properties, set ratings
Playlistslist, create, delete, rename, add tracks, remove tracks, get tracks
AirPlaylist devices, select device, current device

Track Properties (Read)

tell application "Music"
    set t to current track
    -- Basic info
    name of t           -- "Hey Jude"
    artist of t         -- "The Beatles"
    album of t          -- "1 (Remastered)"
    album artist of t   -- "The Beatles"
    composer of t       -- "Lennon-McCartney"
    genre of t          -- "Rock"
    year of t           -- 1968

    -- Timing
    duration of t       -- 431.0 (seconds)
    time of t           -- "7:11" (formatted)
    start of t          -- start time in seconds
    finish of t         -- end time in seconds

    -- Track info
    track number of t   -- 21
    track count of t    -- 27
    disc number of t    -- 1
    disc count of t     -- 1

    -- Ratings
    rating of t         -- 0-100 (20 per star)
    loved of t          -- true/false
    disliked of t       -- true/false

    -- Playback
    played count of t   -- 42
    played date of t    -- date last played
    skipped count of t  -- 3
    skipped date of t   -- date last skipped

    -- IDs
    persistent ID of t  -- "ABC123DEF456"
    database ID of t    -- 12345
end tell

Track Properties (Writable)

tell application "Music"
    set t to current track
    set rating of t to 80          -- 4 stars
    set loved of t to true
    set disliked of t to false
    set name of t to "New Name"    -- rename track
    set genre of t to "Alternative"
    set year of t to 1995
end tell

Player State Properties

tell application "Music"
    player state          -- stopped, playing, paused, fast forwarding, rewinding
    player position       -- current position in seconds (read/write)
    sound volume          -- 0-100 (read/write)
    mute                  -- true/false (read/write)
    shuffle enabled       -- true/false (read/write)
    shuffle mode          -- songs, albums, groupings
    song repeat           -- off, one, all (read/write)
    current track         -- track object
    current playlist      -- playlist object
    current stream URL    -- URL if streaming
end tell

Playback Commands

tell application "Music"
    -- Play controls
    play                          -- play current selection
    pause
    stop
    resume
    playpause                     -- toggle play/pause
    next track
    previous track
    fast forward
    rewind

    -- Play specific content
    play (first track of library playlist 1 whose name contains "Hey Jude")
    play user playlist "Road Trip"

    -- Settings
    set player position to 60     -- seek to 1:00
    set sound volume to 50        -- 0-100
    set mute to true
    set shuffle enabled to true
    set song repeat to all        -- off, one, all
end tell

Library Queries

tell application "Music"
    -- All library tracks
    every track of library playlist 1

    -- Search by name
    tracks of library playlist 1 whose name contains "Beatles"

    -- Search by artist
    tracks of library playlist 1 whose artist contains "Beatles"

    -- Search by album
    tracks of library playlist 1 whose album contains "Abbey Road"

    -- Combined search
    tracks of library playlist 1 whose name contains "Hey" and artist contains "Beatles"

    -- By genre
    tracks of library playlist 1 whose genre is "Rock"

    -- By year
    tracks of library playlist 1 whose year is 1969

    -- By rating
    tracks of library playlist 1 whose rating > 60  -- 3+ stars

    -- Loved tracks
    tracks of library playlist 1 whose loved is true

    -- Recently played (sort by played date)
    tracks of library playlist 1 whose played date > (current date) - 7 * days
end tell

Playlist Operations

tell application "Music"
    -- List all playlists
    name of every user playlist

    -- Get playlist
    user playlist "Road Trip"
    first user playlist whose name contains "Road"

    -- Create playlist
    make new user playlist with properties {name:"New Playlist", description:"My playlist"}

    -- Delete playlist
    delete user playlist "Old Playlist"

    -- Rename playlist
    set name of user playlist "Old Name" to "New Name"

    -- Get playlist tracks
    every track of user playlist "Road Trip"
    name of every track of user playlist "Road Trip"

    -- Add track to playlist (must be library track)
    set targetPlaylist to user playlist "Road Trip"
    set targetTrack to first track of library playlist 1 whose name contains "Hey Jude"
    duplicate targetTrack to targetPlaylist

    -- Remove track from playlist
    delete (first track of user playlist "Road Trip" whose name contains "Hey Jude")

    -- Playlist properties
    duration of user playlist "Road Trip"   -- total duration
    time of user playlist "Road Trip"       -- formatted duration
    count of tracks of user playlist "Road Trip"
end tell

AirPlay

tell application "Music"
    -- List AirPlay devices
    name of every AirPlay device

    -- Get current device
    current AirPlay devices

    -- Set output device
    set current AirPlay devices to {AirPlay device "Living Room"}

    -- Multiple devices
    set current AirPlay devices to {AirPlay device "Living Room", AirPlay device "Kitchen"}

    -- Device properties
    set d to AirPlay device "Living Room"
    name of d
    kind of d           -- computer, AirPort Express, Apple TV, AirPlay device, Bluetooth device
    active of d         -- true if playing
    available of d      -- true if reachable
    selected of d       -- true if in current devices
    sound volume of d   -- 0-100
end tell

String Escaping

Always escape user input:

def escape_applescript(s):
    return s.replace('\\', '\\\\').replace('"', '\\"')

safe_name = escape_applescript(user_input)
script = f'tell application "Music" to play user playlist "{safe_name}"'

Limitations

  • No catalog access - only library content
  • macOS only - no Windows/Linux

MusicKit API

Cross-platform but requires Apple Developer account ($99/year) and token setup.

Authentication

Requirements:

  1. Apple Developer account
  2. MusicKit key (.p8 file) from developer portal
  3. Developer token (JWT, 180 day max)
  4. User music token (browser OAuth)

Generate developer token:

import jwt, datetime

with open('AuthKey_XXXXXXXXXX.p8') as f:
    private_key = f.read()

token = jwt.encode(
    {
        'iss': 'TEAM_ID',
        'iat': int(datetime.datetime.now().timestamp()),
        'exp': int((datetime.datetime.now() + datetime.timedelta(days=180)).timestamp())
    },
    private_key,
    algorithm='ES256',
    headers={'alg': 'ES256', 'kid': 'KEY_ID'}
)

Get user token: Browser OAuth to https://authorize.music.apple.com/woa

Headers for all requests:

Authorization: Bearer {developer_token}
Music-User-Token: {user_music_token}

Base URL: https://api.music.apple.com/v1

Available Endpoints

Catalog (Public - dev token only)

EndpointMethodDescription
/catalog/{storefront}/searchGETSearch songs, albums, artists, playlists
/catalog/{storefront}/songs/{id}GETSong details
/catalog/{storefront}/albums/{id}GETAlbum details
/catalog/{storefront}/albums/{id}/tracksGETAlbum tracks
/catalog/{storefront}/artists/{id}GETArtist details
/catalog/{storefront}/artists/{id}/albumsGETArtist's albums
/catalog/{storefront}/artists/{id}/songsGETArtist's top songs
/catalog/{storefront}/artists/{id}/related-artistsGETSimilar artists
/catalog/{storefront}/playlists/{id}GETPlaylist details
/catalog/{storefront}/chartsGETTop charts
/catalog/{storefront}/genresGETAll genres
/catalog/{storefront}/search/suggestionsGETSearch autocomplete
/catalog/{storefront}/stations/{id}GETRadio station

Library (Requires user token)

EndpointMethodDescription
/me/library/songsGETAll library songs
/me/library/albumsGETAll library albums
/me/library/artistsGETAll library artists
/me/library/playlistsGETAll library playlists
/me/library/playlists/{id}GETPlaylist details
/me/library/playlists/{id}/tracksGETPlaylist tracks
/me/library/searchGETSearch library
/me/libraryPOSTAdd to library
/catalog/{sf}/songs/{id}/libraryGETGet library ID from catalog ID

Playlist Management

EndpointMethodDescription
/me/library/playlistsPOSTCreate playlist
/me/library/playlists/{id}/tracksPOSTAdd tracks to playlist

Personalization

EndpointMethodDescription
/me/recommendationsGETPersonalized recommendations
/me/history/heavy-rotationGETFrequently played
/me/recent/playedGETRecently played
/me/recent/addedGETRecently added

Ratings

EndpointMethodDescription
/me/ratings/songs/{id}GETGet song rating
/me/ratings/songs/{id}PUTSet song rating
/me/ratings/songs/{id}DELETERemove rating
/me/ratings/albums/{id}GET/PUT/DELETEAlbum ratings
/me/ratings/playlists/{id}GET/PUT/DELETEPlaylist ratings

Storefronts

EndpointMethodDescription
/storefrontsGETAll storefronts
/storefronts/{id}GETStorefront details
/me/storefrontGETUser's storefront

Common Query Parameters

ParameterDescriptionExample
termSearch queryterm=beatles
typesResource typestypes=songs,albums
limitResults per page (max 25)limit=10
offsetPagination offsetoffset=25
includeRelated resourcesinclude=artists,albums
extendAdditional attributesextend=editorialNotes
lLanguage codel=en-US

Search Example

GET /v1/catalog/us/search?term=wonderwall&types=songs&limit=10

Response:
{
  "results": {
    "songs": {
      "data": [{
        "id": "1234567890",
        "type": "songs",
        "attributes": {
          "name": "Wonderwall",
          "artistName": "Oasis",
          "albumName": "(What's the Story) Morning Glory?",
          "durationInMillis": 258773,
          "releaseDate": "1995-10-02",
          "genreNames": ["Alternative", "Music"]
        }
      }]
    }
  }
}

Library-First Workflow (Complete)

Adding a catalog song to a playlist requires 4 API calls:

import requests

headers = {
    "Authorization": f"Bearer {dev_token}",
    "Music-User-Token": user_token
}

# 1. Search catalog
r = requests.get(
    "https://api.music.apple.com/v1/catalog/us/search",
    headers=headers,
    params={"term": "Wonderwall Oasis", "types": "songs", "limit": 1}
)
catalog_id = r.json()['results']['songs']['data'][0]['id']

# 2. Add to library
requests.post(
    "https://api.music.apple.com/v1/me/library",
    headers=headers,
    params={"ids[songs]": catalog_id}
)

# 3. Get library ID (catalog ID → library ID)
r = requests.get(
    f"https://api.music.apple.com/v1/catalog/us/songs/{catalog_id}/library",
    headers=headers
)
library_id = r.json()['data'][0]['id']

# 4. Add to playlist (library IDs only!)
requests.post(
    f"https://api.music.apple.com/v1/me/library/playlists/{playlist_id}/tracks",
    headers={**headers, "Content-Type": "application/json"},
    json={"data": [{"id": library_id, "type": "library-songs"}]}
)

Create Playlist

POST /v1/me/library/playlists
Content-Type: application/json

{
  "attributes": {
    "name": "Road Trip",
    "description": "Summer vibes"
  },
  "relationships": {
    "tracks": {
      "data": []
    }
  }
}

Ratings

# Love a song (value: 1 = love, -1 = dislike)
PUT /v1/me/ratings/songs/{id}
Content-Type: application/json

{"attributes": {"value": 1}}

Limitations

  • No playback control - API cannot play/pause/skip
  • Playlist editing - can only modify API-created playlists
  • Token management - dev tokens expire every 180 days
  • Rate limits - Apple enforces request limits

Common Mistakes

❌ Using catalog IDs in playlists:

# WRONG
json={"data": [{"id": "1234567890", "type": "songs"}]}

Fix: Add to library first, get library ID, then add.

❌ Playing catalog songs via AppleScript:

# WRONG
play track id "1234567890"

Fix: Song must be in library.

❌ Unescaped AppleScript strings:

# WRONG
name = "Rock 'n Roll"
script = f'tell application "Music" to play playlist "{name}"'

Fix: Escape quotes.

❌ Expired tokens: Dev tokens last 180 days max. Fix: Check expiration, handle 401 errors.


The Easy Way: mcp-applemusic

The mcp-applemusic MCP server handles all this complexity automatically: AppleScript escaping, token management, library-first workflow, ID conversions.

Install:

git clone https://github.com/epheterson/mcp-applemusic.git
cd mcp-applemusic && python3 -m venv venv && source venv/bin/activate
pip install -e .

Configure Claude Desktop:

{
  "mcpServers": {
    "Apple Music": {
      "command": "/path/to/mcp-applemusic/venv/bin/python",
      "args": ["-m", "applemusic_mcp"]
    }
  }
}

On macOS, most features work immediately. For catalog features or Windows/Linux, see the repo README.

Manualmcp-applemusic
4 API calls to add songplaylist(action="add", auto_search=True)
AppleScript escapingAutomatic
Token managementAutomatic with warnings

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

1password

無料

Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.

日本語の概要は準備中です。原文の説明を表示しています。

sundial-org/awesome-openclaw-skills6712026年3月7日 更新

A股实时行情与分时量能分析。获取沪深股票实时价格、涨跌、成交量,分析分时量能分布(早盘/尾盘放量)、主力动向(抢筹/出货信号)、涨停封单。支持持仓管理和盈亏分析。Use when: (1) 查询A股实时行情, (2) 分析主力资金动向, (3) 查看分时成交量分布, (4) 管理股票持仓, (5) 分析持仓盈亏。

日本語の概要は準備中です。原文の説明を表示しています。

sundial-org/awesome-openclaw-skills6712026年3月7日 更新

Scan HTML and JSX for accessibility issues with AI-powered fix suggestions

日本語の概要は準備中です。原文の説明を表示しています。

sundial-org/awesome-openclaw-skills6712026年3月7日 更新

When the user wants to plan, design, or implement an A/B test or experiment. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," or "hypothesis." For tracking implementation, see analytics-tracking.

日本語の概要は準備中です。原文の説明を表示しています。

sundial-org/awesome-openclaw-skills6712026年3月7日 更新

Multi-channel ABM automation that turns LinkedIn URLs into coordinated outbound campaigns. Scrapes profiles, enriches with Apollo (email + phone), gets mailing addresses via Skip Trace, then orchestrates email sequences, LinkedIn touches, and handwritten letters via Scribeless. The secret weapon for standing out in crowded inboxes.

日本語の概要は準備中です。原文の説明を表示しています。

sundial-org/awesome-openclaw-skills6712026年3月7日 更新

accli

無料

This skill should be used when interacting with Apple Calendar on macOS. Use it for listing calendars, viewing events, creating/updating/deleting calendar events, and checking availability/free-busy times. Triggers on requests like "check my calendar", "schedule a meeting", "what's on my schedule", "am I free tomorrow", or any calendar-related operations.

日本語の概要は準備中です。原文の説明を表示しています。

sundial-org/awesome-openclaw-skills6712026年3月7日 更新

sundial-org のスキルをすべて見る

このスキルの問題を報告する