0

我有一个在文件夹中添加或更新文件的脚本。我想要做的是一个applescript将这些文件添加到iTunes。但我似乎无法遍历目录。

tell application "iTunes"
  if playlist myPlaylist exists then delete playlist myPlaylist
  set newPlaylist to (make new user playlist with properties {name:myPlaylist})

  repeat with theFile in myPath as list
    add theFile to playlist myPlaylist
  end repeat
end tell

对于每次重复,theFile 的值是 myPath 的单个字符,而不是 myPath 中的实际文件。theFile 将是 M, a, c, i, n, ... 而不是 file1.mov, file2.mov, ...

谢谢你。

4

1 回答 1

1

如果myPath是字符串,as list则将其转换为字符数组。

您可以告诉 Finder 获取别名列表:

tell application "Finder"
    set l to items of (POSIX file "/Users/username/Music/folder" as alias) as alias list
end tell
tell application "iTunes"
    if playlist "test" exists then
        delete tracks of playlist "test"
    else
        set p to make new user playlist with properties {name:"test"}
    end if
    add l to p
end tell

这会将选定的文件添加到当前显示的播放列表中:

tell application "Finder"
    set l to selection as alias list
end tell
tell application "iTunes"
    add l to view of browser window 1
end tell
于 2013-01-03T01:23:23.273 回答