yomiya

Songs View Fix for Music.app

Aug 26th, 2025
132
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.50 KB | Fixit | 0 0
  1. # --- 準備: プロセス停止 ---
  2. killall Music 2>/dev/null || true
  3. killall cfprefsd 2>/dev/null || true
  4.  
  5. # --- libID を自動検出 ---
  6. local libid=""
  7. local p
  8. for p in \
  9.     "$HOME/Library/Preferences/com.apple.Music.plist" \
  10.     "$HOME/Library/Containers/com.apple.Music/Data/Library/Preferences/com.apple.Music.plist"
  11. do
  12.     if [ -f "$p" ]; then
  13.         libid=$(plutil -p "$p" 2>/dev/null | grep -Eo 'PPr4:LIB:[0-9a-f]+' | awk -F: '{print tolower($3)}' | head -1)
  14.         [ -n "$libid" ] && break
  15.     fi
  16. done
  17.  
  18. if [ -z "$libid" ]; then
  19.     # .musiclibrary の Preferences.plist から拾う(ホーム&外部ボリューム)
  20.     while IFS= read -r libpkg; do
  21.         [ -n "$libpkg" ] || continue
  22.         local pref="$libpkg/Preferences.plist"
  23.         if [ -f "$pref" ]; then
  24.             libid=$(plutil -p "$pref" 2>/dev/null | awk -F'"' '/Library Persistent ID/ {print tolower($4)}' | head -1)
  25.             [ -n "$libid" ] && break
  26.         fi
  27.     done < <(mdfind -name "Music Library.musiclibrary" -onlyin "$HOME/Music" 2>/dev/null; \
  28.                      mdfind -name "Music Library.musiclibrary" -onlyin "/Volumes" 2>/dev/null)
  29. fi
  30.  
  31. if [ -z "$libid" ]; then
  32.     echo "ERROR: libID を自動検出できませんでした。Music を一度起動→終了するか、手動でキーが1件作成されていることを確認してください。"
  33.     return 1
  34. fi
  35. echo "libID=$libid"
  36.  
  37. # --- 総数取得 ---
  38. local COUNT
  39. COUNT=$(osascript -e 'tell application "Music" to launch' \
  40.                                     -e 'tell application "Music" to count of user playlists')
  41. if ! echo "$COUNT" | grep -qE '^[0-9]+$'; then
  42.     echo "ERROR: プレイリスト件数を取得できませんでした。Automation 権限(Terminal→Music)をご確認ください。"
  43.     return 2
  44. fi
  45. echo "playlists=$COUNT"
  46.  
  47. # --- 1件ずつ PID を取り vMF=4 を設定 ---
  48. local i PID KEY
  49. for i in $(seq 1 "$COUNT"); do
  50.     PID=$(osascript -e 'tell application "Music" to try
  51.         return persistent ID of item '"$i"' of user playlists
  52.     on error
  53.         return ""
  54.     end try' | tr '[:upper:]' '[:lower:]')
  55.  
  56.     if echo "$PID" | grep -qE '^[0-9a-f]{16}$'; then
  57.         KEY="PPr4:LIB:${libid}:${PID}"
  58.         defaults write com.apple.Music "$KEY" -dict-add viewModeForPlaylist -int 4
  59.         printf 'OK\t%02d\t%s\n' "$i" "$PID"
  60.     else
  61.         printf 'SKIP\t%02d\n' "$i"
  62.     fi
  63. done
  64.  
  65. # --- 反映&サマリ ---
  66. killall cfprefsd 2>/dev/null || true
  67.  
  68. plutil -p "$HOME/Library/Preferences/com.apple.Music.plist" \
  69.     | grep -Eo 'PPr4:LIB:[0-9a-f]+:[0-9a-f]{16}' | wc -l
  70. plutil -p "$HOME/Library/Preferences/com.apple.Music.plist" \
  71.     | grep -E '"viewModeForPlaylist" => 4' | wc -l
Advertisement
Comments
  • yomiya
    9 days (edited)
    # text 0.47 KB | 0 0
    1. macOS Ventura/Sonoma/Sequoiaで、プレイリストを開くとMusic.appがクラッシュしてしまう人向けのプログラム。
    2. ~/Library/Preferences/com.apple.Music.plist を編集し、プレイリストの表示設定を「曲ごとに表示」に統一します。
    3.  
    4. A program for people whose Music.app crashes when opening playlists on macOS Ventura/Sonoma/Sequoia.
    5. It edits ~/Library/Preferences/com.apple.Music.plist to unify playlist view settings to “Songs.”
Add Comment
Please, Sign In to add comment