|
|
A script to display the current iTunes song's lyrics
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
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.05 seconds |
|