• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[example]: Applescript and Quicktime, converting time string to movie location
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[example]: Applescript and Quicktime, converting time string to movie location


  • Subject: [example]: Applescript and Quicktime, converting time string to movie location
  • From: Jaime Magiera <email@hidden>
  • Date: Wed, 15 Aug 2007 03:51:40 -0400

Hey folks,

I wrote this as an example for someone on the QT API list. It's simple, but might be useful to folks getting their feet wet in Applescript for Quicktime.

Jaime

Begin forwarded message:
From: Jaime Magiera <email@hidden>
Date: August 15, 2007 3:34:34 AM GMT-04:00
Cc: email@hidden
Subject: Re: Absolute times and quicktime/Apple Script

Hello,

Yes, you will have to do the math to calculate the time in ticks. It's quite easy though. Below is a simple applescript with comments to demonstrate the process. Have fun.

Jaime Magiera
Sensory Research
http://www.sensoryresearch.net


(* Begin Script *)

-- Obtain a time string from the user
set targetTimeString to text returned of (display dialog "Please enter a target time of the format hh:mm:ss:ff" default answer "")


tell application "QuickTime Player"
tell document 1

-- Get the time scale, i.e. the number of tics per second
set targetTimeScale to time scale

-- A call to the calculateTime method, with the desired time string and the movie's scale
set targetIndex to my calculateTime(targetTimeString, targetTimeScale)

-- Set movie's index based on the result
set current time to targetIndex

end tell
end tell


return ("Time string " & targetTimeString & " = " & (targetIndex as integer) & " ticks")


-- Multiply the components of the timestring by their respective scale and seconds
on calculateTime(timeString, movieScale)
try
set AppleScript's text item delimiters to ":"
set timeComponentArray to text items of timeString
set msTics to ((((item 4 of timeComponentArray) as number) * (movieScale * 0.01)))
set secTics to (((item 3 of timeComponentArray) as number) * movieScale)
set minTics to (((item 2 of timeComponentArray) as number) * (movieScale * 60))
set hrTics to (((item 1 of timeComponentArray) as number) * (movieScale * 3600))
set timeValue to (msTics + secTics + minTics + hrTics)
return timeValue
on error err
display dialog "Could not calculate a duration from the string that was entered."
return 0
end try
end calculateTime


(* End Script *)



Jaime Magiera Sensory Research Network http://www.sensoryresearch.net



_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Prev by Date: Re: Get Random number?
  • Next by Date: Re: iWork Numbers
  • Previous by thread: Trouble getting AppleScript to execute an Automator app multiple times
  • Next by thread: XCode TableView Script Error....
  • Index(es):
    • Date
    • Thread