タグ「iTunes」での検索

AppleScriptでミュージック.app(旧iTunes)で再生中の曲の情報を取得・操作する

(2026年11月更新:iTunes から「ミュージック」アプリ向けに書き直し、「iTunesで再生中の曲のアートワークを Amazonと Googleで検索する方法」の内容をこの記事にまとめました)

macOS Catalina 以降、iTunes は「ミュージック」アプリに変わりました。AppleScript では tell application "iTunes" を tell application "Music" に書き換えると、ほぼ同じように動きます。

● スクリプトの保存場所と実行方法

  1. 「スクリプトエディタ」(アプリケーション → ユーティリティ)を開き、メニューの「スクリプトエディタ」→「設定...」→「一般」で「メニューバーにスクリプトメニューを表示」にチェックを付けます。
  2. 作ったスクリプトを次のフォルダに保存します(フォルダが無ければ作ります)。
~/Library/Scripts/Applications/Music/

ミュージック.app を前面にしているとき、メニューバーのスクリプトメニューに表示され、そこから実行できます。

● 再生中の曲の情報を取得する

tell application "Music"
    set t to current track
    set trackName to name of t
    set trackArtist to artist of t
    set trackAlbum to album of t
    set trackGenre to genre of t
    set trackRating to rating of t
end tell
display dialog trackArtist & " / " & trackAlbum & " / " & trackName

Mac に保存されている曲の場合は、次のようにファイルの場所も取得できます(Apple Music のストリーミング再生中の曲では取得できません)。

tell application "Music"
    set fileLocation to location of current track
end tell

● 再生中の曲のアートワークを Amazon と Google で検索する

tell application "Music"
    set trackAlbum to album of current track
    set trackArtist to artist of current track
end tell
set q to trackArtist & " " & trackAlbum
open location "https://www.amazon.co.jp/s?k=" & q
open location "https://www.google.com/search?tbm=isch&q=" & q

● 再生中の曲を別のアプリで開く

例として、耳コピ用のアプリ「Amazing Slow Downer」で開きます。

tell application "Music"
    set fileLocation to location of current track
end tell
tell application "Finder"
    open fileLocation using (path to application "Amazing Slow Downer")
end tell

● ミュージック.app を操作する

tell application "Music"
    playpause      -- 再生・一時停止
    next track     -- 次の曲へ
    previous track -- 前の曲へ
    back track     -- 曲の先頭へ(先頭なら前の曲へ)
    set sound volume to 50 -- 音量(0〜100)
end tell

使える命令の一覧は、スクリプトエディタの「ウインドウ」→「ライブラリ」→「ミュージック」で確認できます。


No.127
11/03 10:42

edit

添付ファイル

iTunes
AppleScript