Whack the Current Track

If you find the currently playing track is a real dud, quickly remove it from iTunes.

When that song you positively can’t stand turns up in a Smart Playlist or Party Shuffle and plays, use this AppleScript hack to remove it completely from iTunes and move its file to the Trash.

The Code

This script checks for a current track and gets its databaseIDand locationproperties. The track is removed from iTunes’ main library, thus removing it from all playlists, and the locationproperty (its file path) is used to move its file to the Trash.

tell application "iTunes"
  if player state is not stopped then

   -- dialog is optional
   display dialog "Are you SURE you want to delete " & ¬ "every copy of the currently playing track?" default button 1 -- set some variables set lib to library playlist 1 set curP to current playlist set theTrack to current track -- get some track properties set dbid to theTrack's database ID set trackClass to theTrack's class -- move to next track before deleting current if player state is playing then next track -- init theLoc variable set theLoc to missing value if trackClass is file track then set theLoc to theTrack's location end if -- delete from current playlist delete (some track of curP whose database ID is dbid) -- delete from iTunes try delete (some track of lib whose database ID is dbid) end try set dd_message to "Done. The track has been  ...

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.