Trash Track.scpt

shiftdot515 Jul 27th, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tell application "iTunes"
  2.     set sel to selection
  3.     if sel is {} then
  4.         set is_ct to player position is not missing value
  5.         if is_ct then set sel to current track as list
  6.     end if
  7.     set ditext to "Trash " & (count sel)
  8.     if (count sel) is not 1 then
  9.         set ditext to (ditext & " tracks?")
  10.     else
  11.         set ditext to (ditext & " track?")
  12.     end if
  13.     display dialog ditext buttons {"Yes, delete.", "No, Cancel"} default button 2
  14.     if button returned of result = "Yes, delete." then
  15.         repeat with T in sel
  16.             try -- audio streams don't have locations
  17.                 set L to location of T
  18.             on error errMSG number errNUM
  19.                 if errNUM = -1728 then
  20.                     set L to missing value
  21.                 else
  22.                     error errMSG number errNUM
  23.                 end if
  24.             end try
  25.             set N to name of T
  26.             set in_lib to missing value
  27.             if L is not missing value then -- typical branch for files
  28.                 repeat with R in search playlist "Library" for N only songs
  29.                     if location of R is L then
  30.                         set in_lib to R
  31.                         exit repeat
  32.                     end if
  33.                 end repeat
  34.                 if in_lib is not missing value then
  35.                     delete in_lib
  36.                     tell application "Finder"
  37.                         delete L -- otherwise the file just dangles
  38.                     end tell -- but, empty folders will still dangle
  39.                 end if
  40.             else -- branch for audiosstreams interradio etc deletes all matching url addess
  41.                 if class of T is URL track then
  42.                     set A to address of T
  43.                     repeat with R in search playlist "Library" for N only songs
  44.                         if address of R is equal to A and class of R is equal to class of T then
  45.                             delete R
  46.                         end if
  47.                     end repeat
  48.                 else
  49.                     error "Dont know what to do!!!" number -1
  50.                 end if
  51.             end if
  52.         end repeat
  53.     end if
  54. end tell
  56. -- Trash Track: Find song in Library and delete it.
  57. -- Allows one to delete files w/o having to find them in the Library.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand