You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Music AppleScript获取曲目名称并将标题读取为字符串?

解决Music AppleScript无法读取曲目标题字符串的问题

问题原因

你当前的代码里,log title of tr没有拿到实际的曲目标题字符串,反而输出了AppleScript的对象引用表达式。这是因为遍历every track时,tr是一个应用对象引用,直接访问属性并log时,AppleScript不会自动把它转换成实际字符串。

解决方案

方法1:先存变量再输出

把曲目标题先赋值给变量,再log变量,这样会强制AppleScript获取实际字符串值:

tell application "Music"
    repeat with tr in every track
        set trackTitle to title of tr
        log trackTitle
    end repeat
end tell

方法2:用get命令强制求值

直接用get命令获取标题的实际值,再传入log:

tell application "Music"
    repeat with tr in every track
        log (get title of tr)
    end repeat
end tell

额外优化

如果你的音乐库曲目很多,遍历every track会比较慢,可以一次性把所有标题拿到列表里再处理,效率更高:

tell application "Music"
    set allTrackTitles to title of every track
    repeat with trackTitle in allTrackTitles
        log trackTitle
    end repeat
end tell

内容的提问来源于stack exchange,提问作者user3310334

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 16:12:03