• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

5. AppleScript for iTunes > 85. Whack the Current Track

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
  delete (some track of lib whose database ID is dbid)
end try

set dd_message to "Done.....removed."

-- if the file exists, move to Trash
if theLoc is not missing value then
    tell application "Finder" to delete theLoc
    set dd_message to dd_message & ¬
      " Its file has been moved to the Trash." 
  on error
    set dd_message to dd_message & ¬
      " However, its file could not be moved to the Trash."
  end try
end if

display dialog dd_message buttons {"Thanks"} ¬
  default button 1 with icon 1

  end if
end tell



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint