Jump to content

iTunes Applescript multipage lyrics


Rich20
 Share

2 posts in this topic

Recommended Posts

Hi everyone!

 

I am trying to create a script that needs to

 

-fetch lyrics of current song playing in iTunes-success

-trim the first 10 lines of text in the lyrics-success

-count the number of lines in the lyrics and split them in groups of 40 lines-success

-Display the groups one after the other as the current song is playing-failure

 

I will then use this script in a Geeklet.

 

on run

set info to ""

tell application "System Events"

set runCount to count (every process whose name is "iTunes")

end tell

if runCount > 0 then

tell application "iTunes"

if player state is playing then

 

set _lyrics to lyrics of current track

set timetotal to duration of current track

set midtime to timetotal / 2

set timetofinish to player position

 

 

if paragraphs of _lyrics ≤ 40 then

 

set fParagraphs to paragraphs 10 thru -1 of _lyrics

set AppleScript's text item delimiters to return

set fContentsNew to fParagraphs as string

set info to fContentsNew as string

 

else

 

set fParagraphs1 to paragraphs 10 thru 40 of _lyrics

set fParagraphs2 to paragraphs 41 thru -1 of _lyrics

set AppleScript's text item delimiters to return

set fContents1 to fParagraphs1 as string

set fContents2 to fParagraphs2 as string

 

if timetofinishmidtime then

set info to fContents1 as string

else

set info to fContents2 as string

 

 

end if

 

 

end if

end if

end tell

end if

return info

end run

 

 

 

Even if the script compiles it is not working and I am a bit confused with the lyrics splitting part.

 

Any help would be greatly appreciated! Thank you

 

Link to comment
Share on other sites

Sucess!

 

Correct script is

 

 

on run

set info to ""

tell application "System Events"

set runCount to count (every process whose name is "iTunes")

end tell

if runCount > 0 then

tell application "iTunes"

if player state is playing then

 

set _lyrics to lyrics of current track

set timetotal to duration of current track

set midtime to timetotal / 2

set thirdtime to timetotal / 3

 

 

set par_count to (count paragraphs in _lyrics)

 

if par_count ≥ 40 then

 

set fParagraphs1 to paragraphs 10 thru 40 of _lyrics

set fParagraphs2 to paragraphs 41 thru -1 of _lyrics

set AppleScript's text item delimiters to return

set fContents1 to fParagraphs1 as string

set fContents2 to fParagraphs2 as string

if player positionmidtime then

set info to fContents1 as string

else

set info to fContents2 as string

 

 

end if

 

 

if par_count ≥ 90 then

 

set fParagraphs1 to paragraphs 10 thru 40 of _lyrics

set fParagraphs2 to paragraphs 41 thru 80 of _lyrics

set fParagraphs3 to paragraphs 81 thru -1 of _lyrics

set AppleScript's text item delimiters to return

set fContents1 to fParagraphs1 as string

set fContents2 to fParagraphs2 as string

set fContents3 to fParagraphs3 as string

 

if timetofinishthirdtime then

set info to fContents1 as string

if player position > thirdtime and player positionthirdtime * 2 then

set info to fContents2 as string

else

set info to fContents3 as string

 

end if

 

 

 

if par_count < 40 then

set fParagraphs to paragraphs 9 thru -1 of _lyrics

set AppleScript's text item delimiters to return

set fContentsNew to fParagraphs as string

set info to fContentsNew as string

 

end if

end if

end if

end if

end if

end tell

end if

return info

end run

 

 

Thank you for having a look. Hope this helps someone.

Link to comment
Share on other sites

 Share

×
×
  • Create New...