Kleines Skript, welches einen einstellbaren Ordner in iTunes importiert und im Anschluss die iTunes Mediatheak auch von nicht mehr vorhandenen Tracks bereinigt.

try
  set defaultFolder to my decode_octal(do shell script "defaults read com.hubionmac.syncfolder2itunes defaultFolder")
  display alert "Change default folder?" & return & return & defaultFolder buttons {"Change", "no changes"} default button {"no changes"} giving up after 2
  if (button returned of the result) as text = "Change" then
    error
  end if
on error
  set defaultFolder to POSIX path of (choose folder)
  do shell script "defaults write com.hubionmac.syncfolder2itunes defaultFolder " & quoted form of defaultFolder
end try
set thefolder to (POSIX file defaultFolder) as alias

with timeout of 99999 seconds
  tell application "iTunes"
    --add thefolder to library
    add thefolder to playlist 1 of source 1
  end tell
end timeout
my remove_missing()

display notification "Done"
on remove_missing()
  tell application "iTunes"
    set the stored_setting to fixed indexing
    set fixed indexing to true
    set sourcename to name of source 1
    tell source sourcename
      set libname to name of playlist 1
      tell playlist libname
        repeat with i from the (count of tracks) to 1 by -1
          try
            if the location of track i is missing value then
              delete track i
              set the remove_counter to the remove_counter + 1
            end if
          end try
        end repeat
      end tell
    end tell
    set fixed indexing to the stored_setting
  end tell
end remove_missing

on decode_octal(str)
  set str to quoted form of str
  set cmd to quoted form of "#!/usr/bin/python 
import sys 

x = sys.argv[1] 
x = x.decode('unicode_escape' ) 
x=x.encode('utf-8') 
print x"
  set cmd_full to "python -c " & cmd & " " & str
  set r to do shell script cmd_full
  return r
end decode_octal

Add a comment

Next Post Previous Post