最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - How to delete a mac music library iCloud track from the library using apple script - Stack Overflow

programmeradmin4浏览0评论

I have a mac music library consisting of local MP3s and iCloud tracks, which are online only or saved encrypted as an M4a file (if I chose to keep the locally). I want to delete any given iCloud track with a script. However, according to ChatGPT, iCloud tracks are somehow protected because they are bound to the iCloud account. Is there any way I can still delete them?

Below you can find the script I am trying to run:

import Foundation

func deleteLocalTrack(named trackName: String, by artistName: String) {
    let scriptSource = """
    tell application "Music"
        repeat with aTrack in (tracks of library playlist 1 whose name is "\(trackName)" and artist is "\(artistName)")
            if location of aTrack is not missing value then
                delete aTrack
            end if
        end repeat
    end tell
    """
    
    let script = NSAppleScript(source: scriptSource)
    var error: NSDictionary?
    script?.executeAndReturnError(&error)
    
    if let error = error {
        print("Error: \(error)")
    } else {
        print("Local track(s) by \(artistName) named '\(trackName)' deleted (if found).")
    }
}

// Usage
deleteLocalTrack(named: "MySong", by: "Artist Name")
发布评论

评论列表(0)

  1. 暂无评论