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'