I got an MP3 audiobook download for Christmas.

The downloaded and unzipped files are named in this manner:

  • 01 Prologue.mp3
  • 02 Chapter 1 - Don't start yappin.mp3
  • 03 Chapter 2 - Stack Exchangin your way to success.mp3
  • 04 Chapter 3 - Don't eat that Unicorn meat and three other warnings.mp3
  • 05 Epilogue.mp3

After syncing them to my iPhone and opening the music app I saw that they are displayed in alphabetical order by title:

  • Don't eat that Unicorn meat and three other warnings.
  • Don't start yappin'!
  • Epilogue
  • Stack Exchangin' your way to success.
  • Prologue

Listening in the order they're presented in while I'm driving is bizarre. Is there a way to sort audio by file name in the music app on iOS 5?

  • Have you tried setting the track number in iTunes and then syncing again? – Loïc Wolff Dec 30 '11 at 15:16

Have you tried setting the track number in iTunes and then syncing again?

itunes get info

  • So it seems you have to do this manually, one file at a time.... kinda annoying.... but at least it works! :) – ClearCloud8 Oct 31 '15 at 2:56

While not actually answering your question, do yourself a favor and select all the files for your audio book, Right-click one of them and choose 'Get Info' opening a dialog, similar to that in Loïc Wolff's answer;

Click the 'Options' category, and change the Media Kind to 'Audiobook'.

Only when something is classified as an Audiobook will you get features such as resuming mid-file. Music will always start from the beginning when you re-select it.

iTunes Get Info Dialog, Choosing Audiobook as Media Kind


I was frustrated by this as well and ended up writing a simple script for just this task using Ruby (which comes pre-installed on MacOS and is available on all OSes) with the taglib library. If you're a little programming savvy, just plug in the directory where the files are into the "mydir" variable and save this script (say as "rename_audio_title_to_filename.rb" ). After running it, the filenames will match the title tag and when you drag them them into Itunes playlists, they will be sorted correctly. You can also change the mp3 to other file formats that are supported.

#! /usr/bin/env ruby

require 'taglib'

mydir = "/path/to/my/audio/files"

Dir.glob "#{mydir}/*mp3" do |filename|
  TagLib::FileRef.open( filename ) do |fileref|
    tag = fileref.tag

    puts "The title is #{tag.title} and will become #{File.basename(filename)}"
    tag.title =  File.basename(filename)


Then just run it:

ruby rename_audio_title_to_filename.rb
  • Actually what would be cool is a script that will parse the track number from the file name and insert it as the Track Number on the metadata... – ClearCloud8 Oct 31 '15 at 2:50

Updated yuvilio's script. This version does not change the title mp3 tag. Instead it extract the number from the file name and writes it as 'track' mp3 tag. The file name is expected to be in the form '232 - your file name.mp3'. If your file name is in different format, you can modify the regular expression /(\d*) -.*/.

#! /usr/bin/env ruby

# The script extrats the number from the beginning of the file name
# of the form '123 - The File.mp3' and save it as a 'track' mp3 tag.
# Based on https://apple.stackexchange.com/a/71220/201515

require 'taglib'

mydir = '/Users/evgenii/Downloads/audio'

Dir.glob "#{mydir}/*mp3" do |filename|
  TagLib::FileRef.open(filename) do |fileref|
    tag = fileref.tag
    track_scan = File.basename(filename).scan(/(\d*) -.*/)
    next if track_scan.empty?
    track = track_scan[0][0].to_i
    tag.track = track
    # tag.title = "#{track_scan[0][0]} - #{tag.title}" # Uncomment to prefix the track number in the title

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .