Deleting Songs From iTunes

From Mac Guides

Jump to: navigation, search

Deleting a song in iTunes is a bit more complicated than one would originally imagine. If you delete a song in iTunes, it may leave the file behind in the library. If you delete the song from the hard drive, it will remain in iTunes as an unplayable entry.

Deleting a song from the Library

Simply press the Delete key. iTunes will confirm that you wish to move the file to the Trash, and delete it's entry in iTunes.

Deleting a song from a Playlist

If iTunes is displaying a playlist, the Delete key will simply remove the song from the playlist, leaving the song itself alone. To delete the song from the Library and send the file to the trash, hold down the Option key.

Deleting a song via AppleScript or Automator

Using AppleScript, a song can be deleted from iTunes using the following script. It both deletes the song from iTunes and moves the song file to the Trash.

on deleteTrack(trackName)
	tell application "iTunes"
		set theTrack to track named trackName of playlist "Library"
		set songFile to location of theTrack
		delete theTrack
	end tell
	tell application "Finder" to delete songFile
end deleteTrack

on run
	deleteTrack("delete_this_track") --Change delete_this_track to the name of the track
end run

It does not appear to be possible to do this with Automator, however, as although there's an action to delete a file in Finder, there is not an action to delete a track in iTunes.