使用 osascript 获取 iTunes 歌词
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于某些原因,iTunes 使用 CR(回车)字符而不是 LF(换行)字符来分隔歌词行。回车 – 嗯,将光标返回到最左边的位置,而不切换到下一行,这就是为什么您只能在终端输出中看到最后一行。通过将输出传输到
tr
实用程序(tr 表示翻译)并使用 shell 转义码\r
和\n< 将 CR 替换为 LF,可以轻松解决此问题。 /代码>:
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
: