Get lyrics from iTunes, adjusted by Ralf Schildan

--
(*
This subroutine gets the lyrics from iTunes of the current track and writes them to a text file. *)
on lyrinfo()

tell application "iTunes"
set ct to current track
set {nom, lyr, art} to {"", "", ""}
tell ct
try
if artist is "" then
set art to (" by " & "unknown artist")
else
set art to (" by " & artist)
end if
if lyrics is "" then
set lyr to return & return & "missing lyrics" -- this adds two line returns after song title & artist
else
set lyr to return & return & lyrics -- this adds two line returns after song title & artist
end if
if name is missing value then
set nom to "unknown track title"
else
set nom to name
end if
end try
end tell
--
basic info (feel free to format your own message!)
set the clipboard to ("\"" & nom & "\"" & art & lyr)
end tell

--
let's create a log file that is constantly updated with the current track's lyrics
set Filename to "ct_lyrics" --Name of the hidden file (remove the period to make visible)
set this_data to (the clipboard) & return as string --Any text here
set target_file to ((path to desktop folder as Unicode text) & Filename) --You can eliminate "Filename" as a variable and type the filename as part of the path (if you wish) but you need a full path
set append_data to false --Set this to false if you want to overwrite, true if you want to add text to an existing file

try --This part writes the file
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
on error
try
close access file target_file
end try
end try

end lyrinfo
--

on alter_playbk()

tell application "iTunes"
set tme to (duration of current track)
set pos to player position
set remain to tme - pos
set rpt_num to round ((remain - 10) / 5)
set xyz to 0
log rpt_num
repeat rpt_num times
set y to name of current track
set z to player position
delay 5
if name of current track is not equal to y then
--display dialog "Track has been changed"
my lyrinfo()
set xyz to 1
exit repeat
else
set pos_buff to {z + 5, z + 6, z + 7, z + 8, z + 9}
if {player position} is not in pos_buff then
--display dialog "Leave the slider alone"
set xyz to 1
exit repeat
end if
end if
end repeat
if xyz is 1 then --this is to rerun the subroutine if normal playback has been modified
my alter_playbk()
end if
end tell

end alter_playbk
--
global trk_list

property goforit : false

--
check if iTunes is running
tell application "System Events"
set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
-- check to see if iTunes is playing
tell application "iTunes"
if player state contains playing then set goforit to true
end tell
if goforit then
my lyrinfo()
--
my alter_playbk()
--
end if
end if