setting the progbar to 0 when no song is playing in iTunes

ok, so I have a progBar that works perfectly fine when a song is playing. But if no song is playing and you go to the tab with the progbar i get a NSInternalscripterror(8). Obviously this is because the progbar doesn’t know what to do when no song is playing. I need to know what to put in so it just sets itself to zero when no song is playing. Here is my code (it’s in an idle handler)

using terms from application "iTunes"
		tell application "iTunes"
			set track_time to the finish of the current track
		end tell
	end using terms from
	tell window "mainWindow"
		set the content of progress indicator "progBar" of tab view item "controller_tab" of tab view "myTab" to 0
		set the maximum value of progress indicator "progBar" of tab view item "controller_tab" of tab view "myTab" to the_time
	end tell
	using terms from application "iTunes"
		tell application "iTunes"
			set trackTime to the player position
			
		end tell
	end using terms from
	increment progress indicator "progBar" of tab view item "controller_tab" of tab view "myTab" of window "mainWindow" by trackTime
	tell application "Finder" to set the visible of every process whose name is "iTunes" to false
	return 1

Why not set a variable PlayState that determines the player state of iTunes, and only advances the progress bar if the status is not ‘stopped’?

tell application "iTunes" to set PlayState to (player state) as text
if PlayState is not equal to "stopped" then
	-- Can update progress bar
end if

well that totally messed up my progbar but maybe i put it in the wrong place. Could you show me my code with your code in it?

hendo,

Try putting the test for player state within the tell app “iTunes” block. Then, test the player state outside that block. If stopped, then set the content of the progress bar to 0.

It should work. I have used the same technique before. As a matter of fact, I like to further set the “visible” of progress indicator to false since an idle progress bar does not really serve much purpose in my opinion except to show where the progress bar is.

Good luck.

archseed

That one works perfect Jaques! Thanks!