【问题标题】:Using AppleScript to delete a set files in iTunes使用 AppleScript 删除 iTunes 中的一组文件
【发布时间】:2013-12-13 21:26:09
【问题描述】:

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

【问题讨论】:

  • 那么大概它可能很简单:告诉应用程序“iTunes”删除(文件夹“路径到这里”的文件,其名称扩展名为“mp3”)?那么,我唯一的另一个问题是如何执行脚本? AppleScripts 是从终端执行的吗?
  • 你应该试试 AppleScript Editor。它在/Applications/Utilities
  • 是的,我很熟悉 AppleScript Editor 应用程序的存在,我只是没有任何使用该语言的经验。

标签: applescript itunes


【解决方案1】:

你真的应该发布代码,即使它是错误的,以显示一些努力。但是,这应该可以帮助您入门。节日快乐。

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

【讨论】:

    【解决方案2】:

    这会将 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      相关资源
      最近更新 更多