Get a Track’s Running Time and File Size

Get the total time and total size of selected tracks.

It’s easy to get the total running time and size of a playlist in iTunes; it appears right along the bottom of the main window, beneath the tracks. If you only want to know about a selection of tracks, though, you’d better break out the calculator—or use this simple script that will display the total time and combined size of just the selected or enabled (checkmarked) tracks.

The Code

This script sums the running time and size of either the selected tracks or the enabled tracks and displays the results in a dialog box:

   tell application "iTunes"

     set lib to view of front window
     set total_size to 0

     set total_duration to 0
     set dd_buttons to {"Cancel", "Enabled", "Selected"}

     -- target  selected or enabled tracks?
     if button returned of ¬
       (display dialog "Show total time and space of " & ¬
         "Selected or Enabled tracks in playlist \"" & (name of lib) & ¬ "\":" buttons dd_buttons default button 2) is "Enabled" then set trackList to every track in lib whose enabled is true else set trackList to selection end if -- conglomerate each track's size and duration repeat with aTrack in trackList try set total_size to total_size + (get aTrack's size) set total_duration to total_duration + (get aTrack's duration) end try end repeat -- convert total bytes to megabytes set dd_size to (round total_size / 1024 / ...

Get iPod and iTunes Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.