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