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


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.
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 | # ]