使用AppleScript删除iTunes中的一组文件

使用AppleScript删除iTunes中的一组文件,applescript,itunes,Applescript,Itunes,所以我有一个朋友,我想帮他。他刚买了一台新的MacBookPro,目前正在将iTunes中的所有音频文件转换为“.mp3”扩展名。之后,他将把这些文件移动到一个外部设备(由于某种原因,它不会播放“.m4a”),然后他想删除.mp3。我在AppleScript方面没有任何经验,但我想知道是否有人有过编写删除所有特定类型文件的脚本的经验。非常感谢您的帮助。您应该发布代码,即使它是错误的,以显示您的努力。然而,这应该让你开始。节日快乐 set targetFolder to (choose folde

所以我有一个朋友,我想帮他。他刚买了一台新的MacBookPro,目前正在将iTunes中的所有音频文件转换为“.mp3”扩展名。之后,他将把这些文件移动到一个外部设备(由于某种原因,它不会播放“.m4a”),然后他想删除.mp3。我在AppleScript方面没有任何经验,但我想知道是否有人有过编写删除所有特定类型文件的脚本的经验。非常感谢您的帮助。

您应该发布代码,即使它是错误的,以显示您的努力。然而,这应该让你开始。节日快乐

set targetFolder to (choose folder)
tell application "Finder" to delete (files of targetFolder whose name extension = "mp3")
或者如果你想递归搜索

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

这会将iTunes库中的所有mp3文件移到垃圾桶中:

tell application "iTunes" to location of tracks where kind is "MPEG audio file"
tell application "Finder" to move result to trash
如果所有mp3文件都在~/Music中,您还可以运行如下命令:

find ~/Music -name \*.mp3 -delete
此脚本从iTunes库中删除未找到其文件的曲目:

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

你读过这篇文章了吗:那么可能是这么简单:告诉应用程序“iTunes”删除(文件夹“path goes here”的文件,其扩展名为“mp3”)?那么,我唯一的另一个问题是如何执行脚本?是否从终端执行AppleScript?您应该尝试AppleScript编辑器。它位于
/Applications/Utilities
中。是的,我很熟悉AppleScript编辑器应用程序的存在,只是我没有任何使用该语言的经验。