Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to display the current iTunes song's lyrics Apps
Here is an applescript that will look up the lyrics of the current song you are listening to in iTunes. Simply cut and paste this code into Script Editor, and save it under ~/Library/Scripts . Call it whatever you want, and it will show up in the scripts menu of iTunes.

The script requires a correct album, artist, and song name. Also, if the repository doesn't have the song, you're out of luck. Still, it's pretty useful to be able to look up lyrics!

[robg adds: To get the script in my iTunes script menu, I had to put it in ~/Library/iTunes/Scripts. Once there, though, it worked as described.]

I apologize the code is a little long...one day I hope to have a site hosting this and others! Comments, criticisms, ideas for anything are always welcome - I'd like to make OS X a better place :)

property nameOfTrack : ""
property nameOfAlbum : ""
property nameOfArtist : ""

tell application "iTunes"
  copy name of current track to nameOfTrack
  copy album of current track to nameOfAlbum
  copy artist of current track to nameOfArtist
  
  set nameOfTrack to my parseWord(nameOfTrack)
  set nameOfAlbum to my parseWord(nameOfAlbum)
  set nameOfArtist to my parseWord(nameOfArtist)
        
  my openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
end tell

on parseWord(myWord)
  set myDelims to {"(", ")", "!", "'", "-", "@", "#", "$", "%", ¨
    "^", "&", "*", "-", "+", "=", ":", ";", ",", ".", "/", "<", ¨
    ">", "?", "{", "}", "[", "]"}
  repeat with currentDelim in myDelims
    set AppleScript's text item delimiters to currentDelim
    set myWords to every text item of myWord
    set AppleScript's text item delimiters to {""}
    set myWord to myWords as string
  end repeat
    
  -- convert double spaces to single
  set AppleScript's text item delimiters to "  "
  set myWords to every text item of myWord
  set AppleScript's text item delimiters to {" "}
  set myWord to myWords as string
       
  -- get rid of spaces    
  set AppleScript's text item delimiters to {" "}
  set myWords to every text item of myWord
  set AppleScript's text item delimiters to {"_"}
  set myWord to myWords as string
  return myWord
end parseWord

on openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
  tell application "Safari"
    activate
    make new document at end of documents
    --set URL of document 1 to "http://www.getlyrics.com/lyrics.php?Artist=" & ¨
      nameOfArtist & "&Album=" & nameOfAlbum & "&Song=" & nameOfTrack
    set URL of document 1 to ¨
      "http://display.lyrics.astraweb.com:2000/display.cgi?" & ¨
      nameOfArtist & ".." & nameOfAlbum & ".." & nameOfTrack
  end tell
end openBrowser
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[36,704 views]  

A script to display the current iTunes song's lyrics | 22 comments | Create New Account
Click here to return to the 'A script to display the current iTunes song's lyrics' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Neat!
Authored by: Jay on Jul 10, '03 12:05:08PM

It does work! Unfortunately, the database does not contain less than popular songs' lyrics, but still, it's a neat trick.



[ Reply to This | # ]
Lesser known songs? Use Google!
Authored by: dustpuppy on Aug 06, '04 06:47:17AM

I came up with this ugly hack only a while ago:

tell application "iTunes"
  set theArtist to the artist of the current track
  set theTitle to the name of the current track
end tell

set theURL to "http://www.google.com/search?q=" & theArtist & "+" & theTitle & "+lyrics&ie=UTF-8&btnI=Google+Search"

tell application "Safari"
  activate
  set the URL of the front document to theURL
end tell

It isn't guaranteed to work, but it actually does, most of the time. And, you're totally independent of some special lyrics site. You always use that one with the best PageRank :)



[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: jc00per on Jul 10, '03 12:09:27PM

I change the script slightly to do a search if you happen to be missing any information. It brings up a list of possible matches for you to choose from.

I suck at apple script.. I just started learning it two hours ago. I haven't really tested my changes more than three times.


property nameOfTrack : ""
property nameOfAlbum : ""
property nameOfArtist : ""

tell application "iTunes"
copy name of current track to nameOfTrack
copy album of current track to nameOfAlbum
copy artist of current track to nameOfArtist

set nameOfTrack to my parseWord(nameOfTrack)
set nameOfAlbum to my parseWord(nameOfAlbum)
set nameOfArtist to my parseWord(nameOfArtist)

my openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
end tell

on parseWord(myWord)
set myDelims to {"(", ")", "!", "'", "-", "@", "#", "$", "%", ¨
"^", "&", "*", "-", "+", "=", ":", ";", ",", ".", "/", "<", ¨
">", "?", "{", "}", "[", "]"}
repeat with currentDelim in myDelims
set AppleScript's text item delimiters to currentDelim
set myWords to every text item of myWord
set AppleScript's text item delimiters to {""}
set myWord to myWords as string
end repeat

-- convert double spaces to single
set AppleScript's text item delimiters to " "
set myWords to every text item of myWord
set AppleScript's text item delimiters to {" "}
set myWord to myWords as string

-- get rid of spaces


set AppleScript's text item delimiters to {" "}
set myWords to every text item of myWord
-- Changed the next line from
-- set AppleScript's text item delimiters to {"_"}
-- to
set AppleScript's text item delimiters to {"+"}
set myWord to myWords as string
return myWord
end parseWord

on openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
tell application "Safari"
activate
make new document at end of documents
--set URL of document 1 to "http://www.getlyrics.com/lyrics.php?Artist=" & ¨
nameOfArtist & "&Album=" & nameOfAlbum & "&Song=" & nameOfTrack

-- Changed the next line from
-- set URL of document 1 to ¨
-- "http://display.lyrics.astraweb.com/?word=" & ¨
-- nameOfArtist & "+" & nameOfAlbum & "+" & nameOfTrack
-- to
set URL of document 1 to ¨
"http://search.lyrics.astraweb.com/?word=" & ¨
nameOfArtist & "..." & nameOfAlbum & "..." & nameOfTrack
end tell
end openBrowser





[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: codesmith on Jul 10, '03 02:40:25PM
You may find this works a little better. It checks for missing data, and builds the query accordingly. If all the data is there, then it just tries to display the song. Also I changed the display url to use print.php instead of lyrics.php to avoid the "No referring page" error.
on openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
	tell application "Safari"
		activate
		make new document at end of documents
		if nameOfArtist = "" and nameOfAlbum = "" then
			set URL of document 1 to ¨
				"http://search.lyrics.astraweb.com/?word=" & nameOfTrack
		else if nameOfTrack = "" and nameOfAlbum = "" then
			set URL of document 1 to ¨
				"http://search.lyrics.astraweb.com/?word=" & nameOfArtist
		else if nameOfTrack = "" and nameOfArtist = "" then
			set URL of document 1 to ¨
				"http://search.lyrics.astraweb.com/?word=" & nameOfAlbum
		else if nameOfArtist = "" then
			set URL of document 1 to ¨
				"http://search.lyrics.astraweb.com/?word=" & ¨
				nameOfAlbum & "..." & nameOfTrack
		else if nameOfAlbum = "" then
			set URL of document 1 to ¨
				"http://search.lyrics.astraweb.com/?word=" & ¨
				nameOfArtist & "..." & nameOfTrack
		else if nameOfTrack = "" then
			set URL of document 1 to ¨
				"http://search.lyrics.astraweb.com/?word=" & ¨
				nameOfArtist & "..." & nameOfAlbum
		else
			set URL of document 1 to "http://www.getlyrics.com/print.php?Artist=" & ¨
				nameOfArtist & "&Album=" & nameOfAlbum & "&Song=" & nameOfTrack
		end if
	end tell
end openBrowser


[ Reply to This | # ]
Some comments
Authored by: hamarkus on Jul 10, '03 12:59:24PM

It works real nice. One thing though: The song must be playing or must have been playing (the loudspeaker icon has to be there), only selecting it is not sufficient. It takes the song currently playing or which played last, i.e. the one with the loudspeaker icon.
If you start up iTunes no song has that icon yet and you get the error message: 'The variable NameofTrack is not defined.' Simply play any song to assign the icon.

As a side note: When I hit the 'Check Syntax' button in the Script Editor, it started iTunes 3 in Classic (to get its Dictionary) and the Editor was stuck showing the spinning disc, with the TrueBlueEnvironment (aka Classic) taking up all the idle processor cycles ... until I figured out that iTunes 3 was asking for my attention to respond to a dialog box which did come to front on its own.



[ Reply to This | # ]
Some comments
Authored by: DougAdams on Jul 10, '03 01:26:21PM
To get the single selected track: set theTrack to (item 1 of selection) Also, it might be good to check for a current track first, then see if there's a selection
tell application "iTunes"
	if player state is playing then
		set theTrack to current track
	else if selection is not {} then
		set theTrack to (item 1 of selection)
	end if
end tell
Cheers,
Doug
Doug's AppleScripts for iTunes

---



[ Reply to This | # ]

Get the lyrics even if iTunes not playing the track.
Authored by: snow white on Jul 22, '03 04:00:09AM

An easy script modification makes it work even if the selected track is not currently playing. Add two "playpause" commands right after the tell command to iTunes, as in--

tell application "iTunes"
playpause
playpause

copy name of current track to nameOfTrack
...

This mod works by toggling the iTunes play/pause button twice.

---
snow white

[ Reply to This | # ]

Google-is-your-friend-edition :-)
Authored by: SwissMike on Jul 10, '03 02:49:52PM

I adapted the script to use Google's "I'm feeling lucky" feature, as my musical taste didn't seem to match the given site. The results are much better for me now, YMMV.

property nameOfTrack : ""
property nameOfAlbum : ""
property nameOfArtist : ""

tell application "iTunes"
copy name of current track to nameOfTrack
copy album of current track to nameOfAlbum
copy artist of current track to nameOfArtist

set nameOfTrack to my parseWord(nameOfTrack)
set nameOfAlbum to my parseWord(nameOfAlbum)
set nameOfArtist to my parseWord(nameOfArtist)

my openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
end tell

on parseWord(myWord)
set myDelims to {"(", ")", "!", "'", "-", "@", "#", "$", "%", ¨
"^", "&", "*", "-", "+", "=", ":", ";", ",", ".", "/", "<", ¨
">", "?", "{", "}", "[", "]"}
repeat with currentDelim in myDelims
set AppleScript's text item delimiters to currentDelim
set myWords to every text item of myWord
set AppleScript's text item delimiters to {""}
set myWord to myWords as string
end repeat

-- convert double spaces to single
set AppleScript's text item delimiters to " "
set myWords to every text item of myWord
set AppleScript's text item delimiters to {" "}
set myWord to myWords as string

-- get rid of spaces
set AppleScript's text item delimiters to {" "}
set myWords to every text item of myWord
set AppleScript's text item delimiters to {"+"}
set myWord to myWords as string
return myWord
end parseWord

on openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
tell application "Safari"
activate
make new document at end of documents
--set URL of document 1 to "http://www.getlyrics.com/lyrics.php?Artist=" & ¨
nameOfArtist & "&Album=" & nameOfAlbum & "&Song=" & nameOfTrack
set URL of document 1 to ¨
"http://www.google.com/search?hl=en&ie=ISO-8859-1&btnI=I%27m+Feeling+Lucky&q=-site:amazon.com+-site:moviepundit.com+" & ¨
nameOfArtist & "+" & nameOfTrack & "+Lyrics"
end tell
end openBrowser


------------
Changes:
- adapted textdelimiters to Google's searchformat
- excluded Amazon.com and Moviepundit.com from the search-results, as they often appeared as result with a site to buy the CD, not the lyrics of the song
- i'm just using the artist and the song, not the album for the search, as with latter one i frequently got "album-overview" sites and not sites specifically for that song as result

Issues:
- Whenever i get a .htm File as a result, Safari downloads it instead of showing it in the browser... How can that be avoided?



[ Reply to This | # ]
Google-is-your-friend-edition :-)
Authored by: demmons65 on Jul 10, '03 08:18:11PM

Tried this version and it went 3 for 3, including a couple songs I figured might not be in anyone's lyric database.

Thanks to all that contributed and inspired the others to improve a good script.

--
d a v e

---
--
d a v e



[ Reply to This | # ]
Google-is-your-friend-edition :-)
Authored by: p4ul13 on Jul 10, '03 11:02:51PM
I like this version. I added one line to mine though. Whenever I got results; Safari would open a blank window and then present the lyrics. I found this annoying, so I made the following change:

on openBrowser(nameOfArtist, nameOfAlbum, nameOfTrack)
tell application "Safari"
activate
close window
make new document at end of documents
set URL of document 1 to ¨
"http://www.google.com/search?hl=en&ie=ISO-8859-1&btnI=I%27m+Feeling+Lucky&q=-site:amazon.com+-site:moviepundit.com+" & ¨
nameOfArtist & "+" & nameOfTrack & "+Lyrics"
end tell
end openBrowser


I'm still trying to figure out the .htm issue mentioned above...

[ Reply to This | # ]
For use with all browsers
Authored by: pwestbro on Jul 11, '03 04:19:52PM
For those that don't want to be forced to use Safari, I have modified the script to open the web page in the default browser:
property nameOfTrack : ""
property nameOfAlbum : ""
property nameOfArtist : ""

tell application "iTunes"
	copy name of current track to nameOfTrack
	copy album of current track to nameOfAlbum
	copy artist of current track to nameOfArtist
	
	set nameOfTrack to my parseWord(nameOfTrack)
	set nameOfAlbum to my parseWord(nameOfAlbum)
	set nameOfArtist to my parseWord(nameOfArtist)
end tell
tell application "Finder"
	open location "http://www.google.com/search?hl=en&ie=ISO-8859-1&btnI=I%27m+Feeling+Lucky&q=-site:amazon.com+-site:moviepundit.com+" & nameOfArtist & "+" & nameOfTrack & "+Lyrics"
end tell

on parseWord(myWord)
	set myDelims to {"(", ")", "!", "'", "-", "@", "#", "$", "%", ¨
		"^", "&", "*", "-", "+", "=", ":", ";", ",", ".", "/", "", "?", "{", "}", "[", "]"}
	repeat with currentDelim in myDelims
		set AppleScript's text item delimiters to currentDelim
		set myWords to every text item of myWord
		set AppleScript's text item delimiters to {""}
		set myWord to myWords as string
	end repeat
	
	-- convert double spaces to single
	set AppleScript's text item delimiters to " "
	set myWords to every text item of myWord
	set AppleScript's text item delimiters to {" "}
	set myWord to myWords as string
	
	-- get rid of spaces
	set AppleScript's text item delimiters to {" "}
	set myWords to every text item of myWord
	set AppleScript's text item delimiters to {"+"}
	set myWord to myWords as string
	return myWord
end parseWord



[ Reply to This | # ]
.htm problem and solution
Authored by: ThreeDayMonk on Jul 11, '03 11:57:52PM

The problem is not a ".htm" problem per se. As far as I can tell, all the .htm files are returned from the same site: www.musicsonglyrics.com. They appear to have set their server up rather badly, so that content-type is set to server-parsed instead of text/html. Even trying to visit the site is impossible in Safari!

That's why Safari downloads it: it doesn't know how to handle it. Compare that with Internet Explorer (Windows version), which tries to guess the format, and therefore happily interprets anything as HTML that looks like it, with predictable, negative consequences for security. Safari behaves correctly, as does Camino. IE:mac doesn't know what to do‚ÄĒit can't handle the page, according to my brief test.

The solution? Add -site:musicsonglyrics.com to the Google request. Works for me.



[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: pjryan on Jul 10, '03 05:16:57PM

Wow, this last script, (submitted by SwissMike) works great!
Impressed with the speed at which it returned the results, accurate too, seven outta seven so far!
I consider my taste in music to be "ecclectic", but others might use a shorter, "four-letter" description. ;) The only qwerk I encountered is that it renders it's results in the tab I'm reading while opening a new window behind the first.
Aside from that, good job!



[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: jonn8n on Jul 10, '03 06:24:55PM
Here's the script I use. Jon
property allowed_URL_chars : (characters of "$-_.+!*'(),1234567890abcdefghijklmnopqrstuvwxyz ")
property hex_list : (characters of "0123456789ABCDEF")

tell application "iTunes"
	activate
	set lib_count to count of tracks of playlist "Library"
	if lib_count = 0 then
		my display_error("You have no tracks in your library. Please try again after you purchase some music.")
		return
	end if
	if player state = playing then
		set the_selection to current track
	else
		set the_selection to selection
		if (count of the_selection) ? 1 then
			set the_selection to item 1 of the_selection
		else if the_selection = {} then
			my display_error("You have no track selected. Select one track and try again.")
			return
		end if
	end if
	copy {"", ""} to {track_name, artist_name}
	tell the_selection to copy {name as string, artist as string} to {track_name, artist_name}
end tell
if artist_name = "" then set track_name to set_value("artist")
if track_name = "" then set track_name to set_value("track")
open location "http://search.lyrics.astraweb.com/?word=" & (encode_URL_string(artist_name)) & "+" & (encode_URL_string(track_name))

on set_value(the_string)
	tell application "iTunes" to return text returned of (display dialog "I couldn't get the " & the_string & " name. What is it?" default answer "" buttons {"OK"} default button 1 with icon 1)
end set_value

on display_error(the_string)
	tell application "iTunes" to display dialog the_string buttons {"OK"} default button 1 with icon 0 giving up after 10
end display_error

on encode_URL_string(this_item)
	set character_list to (characters of this_item)
	repeat with i from 1 to number of items in character_list
		set this_char to item i of character_list
		if this_char is not in allowed_URL_chars then
			set ASCII_num to (ASCII number this_char)
			set item i of character_list to (("%" & (item ((ASCII_num div 16) + 1) of hex_list) & (item ((ASCII_num mod 16) + 1) of hex_list)) as string)
		end if
	end repeat
	set this_item to character_list as string
	set AppleScript's text item delimiters to {" "}
	set this_item to (every text item of this_item) as list
	set AppleScript's text item delimiters to {"+"}
	set this_item to (every text item of this_item) as string
	set AppleScript's text item delimiters to {""}
	return this_item
end encode_URL_string

on atid(the_delim)
	set AppleScript's text item delimiters to the_delim
end atid


[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: Jyri Erik on Jul 10, '03 07:50:09PM

I've found a "problem". Basically, eveything in my iTunes list where the name of the group is preceeded by "The" won't show the lyrics unless I either remove the "the" from the URL line or put the "the" at the end of the group's name. (i.e. "The Beach Boys" has to become "Beach Boys" to find the lyrics, while "The Damned" have to become "Damned_the" to find the lyrics. Is there an easy way to just remove the "the"s before it does the search??

Jyri



[ Reply to This | # ]
AC/DC Fans
Authored by: jbravo on Jul 11, '03 05:24:46PM
Nice script! Unfortunately it removes the forward slash in "AC/DC" and therefore the lyrics are not found for any AC/DC song, or any song where the Artist, Title or Album contains a forward slash. Fortunately this is easy to fix.

1. Remove the forward slash from the myDelims array
2. Convert forward slashes to underscores by adding this before "-- convert double spaces to single"
	-- convert forward slash to under score
	set AppleScript's text item delimiters to "/"
	set myWords to every text item of myWord
	set AppleScript's text item delimiters to {"_"}
	set myWord to myWords as string
I haven't tested this enough to determine if there are negative consequences to this modification, but I can now find AC/DC lyrics without a hitch. I also haven't tested it on the Google version of this script given here.

[ Reply to This | # ]
Revised script
Authored by: Safar on Aug 12, '03 09:01:04AM

I improved this script given ... here are the improvements of my script:

  1. it saves on your hard drive the lyrics
  2. it shows the lyrics at once if they have already been saved
Here is how to install it:
  1. Download the script
  2. open Script Editor (found in Applications -> Applescript)
  3. in the code, change Lyrics_dest : "OS_X:paroles" to an existing folder where you want your lyrics to be saved (on my computer, i used the folder "paroles" of the disk "OS_X" -- paroles means lyrics in French)
  4. save the result in ~/Library -> iTunes -> Scripts and give it the name you want
Here is how to use it:
  1. play the song whose lyrics you want to get
  2. launch the script from the sript menu (see this link from Apple if you don't know how to use the script menu).
  3. Safari should display a page with the Lyrics. If it does not, then forget about saving the lyrics. If it does, you have nine seconds to select the lyrics (this can be set modifying delay_time_to_select).
  4. you're done!
I hope some will find it as useful as i do!

[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: retsamxaw on Aug 12, '03 09:07:56AM
This was such an awesome idea that I didn't have to change much to make it more useful for me: use Google. Google's much more forgiving when your iTunes music is spelled differently than the lyrics database used in the original.

Anyway, here is the AppleScript. Let me know if it doesn't work!

[robg adds: Instead of pasting the script here, I've made it available for download: googleLyrics.scpt.sit.]

[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: vincentpace on Dec 11, '03 11:32:17AM

Does anyone know how to make this work with Japanese/Chinese text????



[ Reply to This | # ]
A script to display the current iTunes song's lyrics
Authored by: ansoni on Jan 04, '04 04:24:27AM
Just downloaded the script and started to play with it.

To enable Japanese you need to edit the google search string that the script uses.
set URL of document 1 to "http://www.google.com/search?btnI=1&ie=UTF-8&oe=UTF-8&q= +lyrics -amazon.com -review" & nameOfTrack & nameOfArtist & nameOfAlbum

This is the new line that I ended up with. Also note that I added a -amazon.com and a -review because I kept getting those for some reason. The important piece on that line is the ie=UTF-8.

[ Reply to This | # ]
A script to display the current iTunes song's tablature
Authored by: indigo7 on Oct 09, '04 10:45:43AM

Hello,

I was wondering if this script could be tweaked/modified to display the song's tablature, instead of lyrics.

As I have over 3,000 songs, it's a pain to keep searching and opening tabs for each song. If I already have the tabs, can I just have the script point to the folder and open it for the current song?

Would really help my guitar practice. Thanks!



[ Reply to This | # ]
A script to display the current iTunes song's tablature
Authored by: livefire on Feb 04, '05 01:24:26PM

This is an awesome script Doug's Actionscripts has something similar that I've been using for a while now, but I have an idea.
I am a DJ at my college radio station and we have to screen music for profanity.
I was thinking that you could use the google 'I'm feeling lucky' feature like you did, copy the output into a text editor, and search the text for profane words.
ie. loop
find "damn"
a+1 -> a
end loop
"damn ="
display a

you'll have to forgive me... I'm just laying the idea down and I don't have any experience beyond basic

any ideas or help with code would be appreciated!

thanx,
(MIKE



[ Reply to This | # ]