A while back I wanted to know what people were listening to if they were sharing my iTunes library. I used lsof in a little bash script to find out.
#!/usr/bin/env bash tunes=`lsof -F -c iTunes | egrep '(\.aac|\.mp3|\.wav|\.aiff|\.m4a|\.m4p|\.m4b)'` if [[ `echo $tunes | wc -l` = 0 ]]; then echo 'iTunes is not using any local files.' elif [[ ${tunes:0:1} = 'n' ]]; then echo ${tunes:1} else echo $tunes fi
Interestingly, I was getting a letter “n” before every file’s path. Instead of tweaking my lsof command I just put stripped off any leading “n” character as I knew all paths would be absolute and hence start with a forward slash. Duh!







