Created
October 2, 2012 19:40
-
-
Save roshanvid/3822802 to your computer and use it in GitHub Desktop.
Display total length of video files dragged onto script icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on open (theList) | |
-- use a repeat loop to loop over a list of something | |
set vidList to {} -- this is where we store the information as we loop over the files | |
set totalTime to 0 | |
repeat with aFile in theList | |
-- get some information from aFile | |
tell application "System Events" | |
set vidFile to movie file (aFile as text) | |
set ts to time scale of vidFile | |
set dur to duration of vidFile | |
set totalTime to totalTime + dur | |
end tell | |
-- add the information to the "storage" list we made earlier | |
set end of vidList to {POSIX path of aFile, secs_to_hms(dur / ts)} | |
end repeat | |
set mins to totalTime div (ts * 60) | |
set secs to (totalTime / ts) mod 60 | |
display dialog secs_to_hms(totalTime / ts) | |
end open | |
(*=================== SUBROUTINES ===================*) | |
-- convert seconds into a string of words | |
-- the use of "mod" and "div" here makes it easy | |
-- we also make sure that each value is at least 2 places long to make it look nicer | |
on secs_to_hms(the_secs) | |
set timeString to "" | |
set hr to the_secs div hours | |
if hr is not 0 then set timeString to timeString & (text -2 thru -1 of ("0" & (hr as text))) & " hours " | |
set min to the_secs mod hours div minutes | |
if min is not 0 then set timeString to timeString & (text -2 thru -1 of ("0" & (min as text))) & " minutes " | |
set sec to the_secs mod minutes div 1 | |
if sec is not 0 then | |
set fraction to text 2 thru 3 of ((100 + the_secs mod 1 * 100) as text) | |
set timeString to timeString & (sec as text) & "." & fraction & " seconds" | |
end if | |
if timeString ends with space then set timeString to text 1 thru -2 of timeString | |
return timeString | |
end secs_to_hms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment