10.4: Move lyrics from Sing that iTunes to pearLyrics

Dec 05, '05 06:40:00AM

Contributed by: Andrew Fletcher

Tiger only hintI used to use the Sing that iTune! widget to insert lyrics into iTunes, but moved to using pearLyrics to avoid a bug. (The bug was that occasionally the lyrics for one song would be put into the iTunes lyrics for a different song).

However, Sing that iTune! also saves lyrics as text files, but names them differently from pearLyrics. So I wrote a UNIX shell script to copy the files and rename them in pearLyrics format. This allows all the lyrics files to be kept together the same way. I thought someone who is learning about shell scripts might want to see it.

The script is:

# 
# copy all "Sing that iTune!" song files to a directory with
# the song filename in pearLyrics format
#
# a directory called sing2pearfiles is created on the desktop 
# to hold the output files, if required.
#

mkdir -p ~/Desktop/sing2pearfiles;

cd ~/Documents/Sing that iTune!/

find . -type f -name *.txt -exec sh -c 'oldname="{}"; newname=$(echo "${oldname#./}" | tr "[:upper:]" "[:lower:]" | tr "/" " "); cp "$oldname" ~/Desktop/sing2pearfiles/"$newname"' ;                                                                               

To use it, paste it into a file and open a Terminal. Then run sh filename. This will create a folder called sing2pearfiles on your desktop. Use the Finder to move the files in that folder to where pearLyrics stores your files (on my Mac, it's ~/Library -> Application Support -> pearLyrics -> lyrics). The Sing that iTunes! files are not removed, so you may want to tidy them yourself.

The script works like this...
  1. mkdir -p ~/Desktop/sing2pearfiles
    Firstly the sing2pearfiles folder is created if it doesn't already exist.
  2. cd ~/Documents/Sing that iTune!/
    find . -type f -name *.txt 
    Then the "Sing that iTune!" lyrics folder is searched for files with names that end with ".txt" using.
  3. -exec sh -c 
    For each of the files a shell script is run.
  4. oldname="{}"; newname=$(echo "${oldname#./}" 
    The names of these files are manipulated to remove "./" from the start.
  5. tr "[:upper:]" "[:lower:]" 
    Any uppercase letters are turned into lowercase.
  6. tr "/" " "
    The directory separator character "/" is turned into a space.
  7. cp "$oldname" ~/Desktop/sing2pearfiles/"$newname"'
    Finally the file is copied.
I hope this explanation helps!

[robg adds: I haven't tested this one...]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20051126123700103