문제

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?

도움이 되었습니까?

해결책

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'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top