Question

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.

Was it helpful?

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")

OTHER TIPS

This moves all mp3 files in the iTunes library to the trash:

tell application "iTunes" to location of tracks where kind is "MPEG audio file"
tell application "Finder" to move result to trash

If all mp3 files are in ~/Music, you could also run a command like this:

find ~/Music -name \*.mp3 -delete

This script removes tracks whose files are not found from the iTunes library:

tell application "iTunes"
    repeat with t in (get file tracks of library playlist 1)
        if location of t is missing value then delete t
    end repeat
end tell
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top