Search code examples
applescriptitunes

Using AppleScript to delete a set files in iTunes


So I have a friend whom I'm trying to help out. He just bought a new MacBook Pro and is currently going through the process of converting all of the audio files in iTunes to a ".mp3" extentsion. Afterwords, he is going to move these files to an external device (it for some reason will not play ".m4a") and then he wants to delete the .mp3s. I do not have any experience in AppleScript but I would like to know if anyone has any any experience with writing a script that deletes all files of a certain type. Any help is much appreciated.


Solution

  • You should really post code, even if it's wrong, to show some effort. However, this should get you started. Happy Holidays.

    set targetFolder to (choose folder)
    tell application "Finder" to delete (files of targetFolder whose name extension = "mp3")
    

    or if you want to search recursively...

    set targetFolder to (choose folder)
    tell application "Finder" to delete (files of (entire contents of targetFolder) whose name extension = "mp3")