Noobie questions...

Hi all

I am very new to AS.

I am trying to work on a script Michael McCracken wrote which takes the current time in a paused Quicktime movie and appends it to an open VoodooPad document. Here it is:

tell application "QuickTime Player"
	set theMovie to document 1
	pause theMovie
	
	set ctime to current time of theMovie
	set tscale to time scale of theMovie
	
	set tseconds to (ctime / tscale)
	
	set str_minutes to (tseconds / 60 div 1) as string
	set str_seconds_left to (tseconds mod 60 div 1) as string
	
	
	
	set theString to str_minutes & ":" & str_seconds_left & " - "
	
	tell application "VoodooPad"
		append text theString to page "Movie" of document 1
	end tell
	
end tell

Okay. Now this works fine, I can call it in Quicksilver (via a trigger) and it will pop the time in my VP doc. My problem is the format the numbers are in.

I’d like to have it as a proper timecode format HH:MM:SS.
However this script inserts the time in a short form, as 9.23 for 9 mins and 23 secs and not 00:09:23.

Is there someway I can set the individual str_minutes and str_seconds to be formatted as double digits always? Or is that something I’d have to have VoodooPad offer, be scriptable and then call that?

And can people suggest how to add in hours here?

Model: MBPro 2.33 core two duo
Browser: Firefox 2.0.0.9
Operating System: Mac OS X (10.5)

Hi Tommy,

try this


tell application "QuickTime Player"
	set theMovie to document 1
	pause theMovie
	
	set ctime to current time of theMovie
	set tscale to time scale of theMovie
	
	tell (ctime / tscale) to set {hr, mn, sc} to {it div hours, it mod hours div minutes, it mod hours mod minutes div 1}
end tell

set theString to paddingZero(hr) & ":" & paddingZero(mn) & ":" & paddingZero(sc) & " - "

tell application "VoodooPad"
 	append text theString to page "Movie" of document 1
end tell

on paddingZero(v)
	return text -2 thru -1 of ("0" & v)
end paddingZero

Edit: or this optimized version:


tell application "QuickTime Player"
	tell document 1
		pause
		tell (current time / time scale) to set theString to my paddingZero(it div hours) & ":" & my paddingZero(it mod hours div minutes) & ":" & my paddingZero(it mod hours mod minutes div 1) & " - "
	end tell
end tell

tell application "VoodooPad"
	 append text theString to page "Movie" of document 1
end tell

on paddingZero(v)
	return text -2 thru -1 of ("0" & v)
end paddingZero

Stefan, how wonderful. Thanks a lot! It works perfectly. I used the second optimized version and absolutely no problems.