scrolling text like in iTunes - I almost got it!

I found this script while searching around that scrolls a text field horizontally when a button is clicked. this is the script:

on clicked the_object
   set object_name to name of the_object as Unicode text
   if object_name = "scroll" then
       tell text field "scroll_text" of window "main"
           set the_string to string value
           repeat with i from 1 to (count the_string)
               set string value to the_string's text i thru -1
               delay 0.1
           end repeat
           set string value to the_string
       end tell
   end if
end clicked

What I want it to do is scroll automatically if the text (the track, artist and album name) is too long. This is my method for handling all the track info, and it’s probably where the code will go.

on tracktext()
	using terms from application "iTunes"
		tell application "iTunes"
			if exists (database ID of current track) then
				set cur_song to (name of the current track as string)
				set cur_artist to (artist of the current track as string)
				set cur_album to (album of the current track as string)
				
				if (count artwork of current track) > 0 then
					set cur_art to data of artwork 1 of the current track as picture
				else
					set cur_art to missing value
				end if
			else
				set cur_song to "No song"
				set cur_artist to "currently"
				set cur_album to "playing"
				set cur_art to missing value
			end if
		end tell
	end using terms from
	
	(* Update the Text Fields *)
	tell tab view item "controller_tab" of tab view "my_tab" of window "mainWindow"
		set content of text field "title_text" to cur_song-- I want this,
		set content of text field "artist_text" to cur_artist--this,
		set content of text field "album_text" to cur_album-- and this to scroll if they are longer than the text field
	end tell
		
	call method "displayArtworkInImageView:trackHasArtwork:" of class "ArtworkController" with parameters {imageView, (cur_art is not missing value)}
end tracktext

Thanks in advance!!

it works pretty good, but one problem is that the track info needs to update when the song is changed. So if I have a return 10 on an on idle handler, wouldn’t I have to wait 10 seconds for the text fields to change to a new song? or is their a way to get around that? Because right now this is my on idle handler:

on idle theObject
	tell application "System Events"
		set iTunesRunning to (name of processes contains "iTunes")
	end tell
	if (not iTunesRunning) then
		quit
	end if
	using terms from application "iTunes"
		tell application "iTunes"
			set sound_volume to sound volume
		end tell
	end using terms from
	tracktext()
	using terms from application "iTunes"
		tell application "iTunes"
			try
				set finish_time to the finish of the current track
			end try
			set track_time to the player position
		end tell
	end using terms from
	tell progress indicator "prog_bar" of tab view item "controller_tab" of tab view "my_tab" of window "mainWindow"
		if track_time is missing value then
			set the content to 0
		else
			set the maximum value to finish_time
			set the content to track_time
		end if
	end tell
	repeat with i from 1 to 3
		if (item i of {t1, t2, t3}) > 15 then -- if number of characters > 15
			my scroll_text_in_field(item i of {"title_text", "artist_text", "album_text"})
		end if
	end repeat
	return 10 -- scroll text of the fields at every 10 seconds
end idle

damn your good:D

EDIT: oh man…one more issue…while the text is scrolling the progress bar doesn’t update until it’s done scrolling…c’mon Jaques 3rd time’s the charm:P

it works perfectly…obviosuly…because Jaques did it…and he is better than sliced bread.:cool: