O'Reilly logo

iPod and iTunes Hacks by Hadley Stern

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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  ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required