Script: iTunes/Edit Track Names in TextMate

This is the fourth in a series of posts about the scripts I use with FastScripts, and it’s yet another iTunes script.

  • Script: Edit Track Names in TextMate
  • Application: iTunes
  • Suggested key binding: ⌃⌘E

This one lets you edit the names of the selected tracks in TextMate.

When triggered, it’ll open a document in TextMate with the name of each track on a new line. You can edit them to your heart’s desire. When you’re done, save and close, and the track metadata will be updated in iTunes for the names that changed.

It’s hardcoded for TextMate. If you’d prefer to use another editor, change the mate -w part to use the command line tool of your editor. I know BBEdit and TextWrangler offer compatible tools. Just use edit -w for them.

Get the standalone script file, or git pull if you’re keeping a git clone of the scripts.

And here it is, in all its glory:

itunes          = Appscript::app("iTunes")
tracks          = itunes.selection.get
old_track_names = { |track| }
new_track_names = Open3::popen3("mate -w") do |stdin, stdout, stderr|
  stdin.puts old_track_names.join("\n")
end, new_track_names)
  .select { |*, old_name, new_name| old_name != new_name    }
  .each   { |track, *,    new_name| new_name }

Notice the awesome ruby 1.9 argument splices in the blocks.

Got comments? Use reddit and/or poke me on twitter.