使用 osascript 获取 iTunes 歌词

发布于 2024-12-25 02:01:34 字数 231 浏览 3 评论 0原文

我正在尝试使用 osascript 获取 iTunes 中当前播放歌曲的歌词。我使用的命令是:

osascript -e '''tell application "iTunes" to lyrics of the current track'''

问题在于,当我在终端上运行它时,我只能获取歌词的最后一行。

是否可以在不先将歌词复制到临时文件的情况下获取完整歌词?

I'm trying to get the lyrics to the current playing song in iTunes using osascript. The command I'm using is:

osascript -e '''tell application "iTunes" to lyrics of the current track'''

The problem with this is that I'm only getting the last line of the lyrics when I run it on the terminal.

Is it possible to get the full lyrics without first copying them to a temp file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2025-01-01 02:01:34

由于某些原因,iTunes 使用 CR(回车)字符而不是 LF(换行)字符来分隔歌词行。回车 – 嗯,将光标返回到最左边的位置,而不切换到下一行,这就是为什么您只能在终端输出中看到最后一行。通过将输出传输到 tr 实用程序(tr 表示翻译)并使用 shell 转义码 \r\n< 将 CR 替换为 LF,可以轻松解决此问题。 /代码>:

osascript -e 'tell application "iTunes" to lyrics of current track' | tr '\r' '\n'

For some reason, iTunes uses the CR (carriage return) character instead of the LF (line feed) character to separate the lines of song lyrics. Carriage return – well, returns the cursor to the leftmost position without switching to the next line, which is why you only see the last line in a Terminal output. This is easily fixed by piping the output to the tr utility (tr for translate) and replacing the CRs by LFs using shell escape codes \r and \n:

osascript -e 'tell application "iTunes" to lyrics of current track' | tr '\r' '\n'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文