Applescript问题 - 将曲目添加到播放列表

时间:2009-02-10 09:44:39

标签: macos applescript

说真的,我很尴尬甚至不敢问这个。

我有一个Applescript,它应该构建一系列整张专辑的播放列表。一切正常,除了实际将曲目添加到播放列表。这是相关的代码:

repeat with theAlbum in randAlbums
    set these_tracks to (tracks of library playlist 1 whose album is theAlbum)
    repeat with the_track in these_tracks
        add the_track to playlist thePlaylist  (* doesn't work *)
    end repeat
end repeat

我得到的错误是“iTunes收到错误:发生描述符类型不匹配。”

randAlbums是唯一相册名称的列表,而thePlaylist是在脚本中先前创建的播放列表。

我一直在抨击这个因为感觉像是一个星期的事情而且我无法弄明白。在此先感谢您提供的任何帮助:)

4 个答案:

答案 0 :(得分:8)

重复是您想要的命令。试试这个:

repeat with theAlbum in randAlbums
    duplicate (tracks of library playlist 1 whose album is theAlbum) to thePlaylist
end repeat

在iTunes界面中,add用于使用文件系统路径向iTunes资料库添加新曲目,而duplicate用于放置对播放列表中现有曲目的引用。 / p>

当使用add命令时,iTunes最终将确定该轨道已经是库的一部分并按照您的意愿行事,但是在它读取文件的元数据之前,没有将其安排用于专辑封面检索等。所有这些相当于一个非常慢的操作,所以如果你在循环中使用它来获取大量曲目,iTunes将会慢慢爬行。

Duplicate执行本机数据库查找并将结果一次性添加到播放列表中,因此速度非常快。

答案 1 :(得分:0)

Applescript非常奇怪......但请查看脚本here dougscripts.com

在添加到播放列表时,看起来他使用重复而不是添加。我正在查看One Song From Each脚本

嗯......怎么样?

add (a reference to the_track) to playlist thePlaylist

答案 2 :(得分:0)

尝试将该行更改为:

add (get location of the_track) to playlist thePlaylist

或者,如果thePlaylist已经是播放列表引用(而不仅仅是播放列表的字符串名称):

add (get location of the_track) to thePlaylist

答案 3 :(得分:0)

尝试:

copy the_track to end of playlist thePlaylist

代替。

相关问题