iTunes - Convert AAC to MP3; then delete AAC

About 1/4 of my library consists of AAC files that I’d like to convert to MP3s. I don’t want duplicate files of the same track, though. I want the AAC file to be deleted. I started with this script as a testing feature…but it fails, telling me “Can’t get kind of track.”

tell application "iTunes"
	if kind of track is ("AAC Audio File") then
	end if
end tell

Can anyone tell me how to get applescript to recognize the “Kind” of track? (AAC OR MP3)
Once I get this part of the script to work, I’m going to replace the beep with “convert track using current encoder” and then delete the AAC file (once I figure out how the heck to do it.)

You’re not telling iTunes which track to use. Perhaps you want to use “current track.”

Okay, So I got this to work:

tell application "iTunes"
	set theTracks to selection
	repeat with aTrack in theTracks
		set newtrack to convert aTrack
		delete aTrack
	end repeat
end tell

However, delete only deletes the file from iTunes. I want to move the AAC file to the trash, removing the file from my Hard Drive to free up space. Any ideas?


This script will take care of it for you. First, however, you need to go into the preferences pane of your iTunes and make sure your encoder is set to mp3 at the quality you want. When this script hits the [convert] command, it will use whatever converter is the default for iTunes.

All the AAC tracks will be selected, converted, and popped into the trash for deletion, as well as removed from your playlist.

set these_files to {}
tell application "iTunes"
	set aac_tracks to every track of the first library playlist whose kind contains "AAC"
	set the track_count to the count of aac_tracks
	display dialog "Processing " & (track_count as string) & " tracks." & ¬
		return & return & ¬
		"This may take a minute. One moment."
	set new_mp3 to (convert aac_tracks)
	repeat with i from 1 to the count of aac_tracks
		set this_track to item i of aac_tracks
		if the location of this_track is not missing value then
			set the end of these_files to (the location of this_track) --stores location of track before deleting it from the playlist
		end if
		delete this_track
	end repeat
end tell
tell application "Finder" --Goes to the Finder for final deletion
	-- delete the files
	set the item_counter to 0
	repeat with i from 1 to the count of these_files
		set this_file to (item i of these_files) as alias
		delete this_file
		set the item_counter to the item_counter + 1
	end repeat
end tell
tell application "iTunes"
	display dialog "Process completed." & return & return & ¬
		(item_counter as string) & " files have been placed in the trash." buttons {"Empty Trash", "OK"} default button 2
	if the button returned of the result is "Empty Trash" then
		ignoring application responses
			tell application "Finder" to empty trash
		end ignoring
	end if
end tell

I know this is some sloppy code and could probably be cleaned up to look much, much better than this, but I just don’t care. The conversion portion is taken from a script I use to make podcasts, and the deletion portion is taken from one of Apple’s iTunes scripts. I do like neat code, but for this, I was more interested in function than form.

Good luck, hope this helps



Thanks for the script. However, it only worked half-way for me.

It seemed to run fine at first. It created a playlist of every AAC track in my library and then used the default encoder to convert them to MP3s. It took my G5 about 2 and a half hours to convert 1,024 tracks.

After that it stopped. The original AAC files weren’t deleted, just deleted from the playlist. I went into my library, sorted by kind to locate the AACs to delete and when prompted, sent the files to the trash.

Not a big deal. Just thought I’d let anybody who reads this know that it won’t deleted the files, just tracks in a playlist.



Thanks for the report. It was most likely a time thing; the script probably timed out while waiting for all the conversions to finish up. I am glad it at least simplifed your workload, however.