applescript通过命令行将歌曲添加到iTunes播放列表

时间:2013-09-08 00:01:17

标签: macos command-line applescript itunes

当我在引号中使用曲目名称时,它会成功将曲目添加到播放列表“会话”。见例:

tell application "iTunes"
    duplicate track "Big Ruby Conf 2013 Keynote by Jim Weirich-vIHdhaF2R2w.mp3" to      playlist "talks"
end tell

但我想要做的是传递我想要添加到播放列表的曲目的命令行参数,如下所示:

on run argv
    tell application "iTunes"
        duplicate track argv to playlist "talks"
    end tell
end run

当我这样做时,我收到此错误:

osascript add_track_to_talks.scpt  "Big Ruby Conf 2013 Keynote by Jim Weirich-vIHdhaF2R2w.mp3"
    add_track_to_talks.scpt: execution error: iTunes got an error: A descriptor type    mismatch occurred. (-10001)

我知道传递命令行参数是有效的,因为我写了一些简单的东西来测试它:

on run arg
    log "hello: " & arg
end run

当我使用此命令运行它时:

osascript log_test.scpt "Blake"

我得到了这个输出:

hello: Blake

关于将轨道名称作为命令行参数传递的正确方法的任何想法?

1 个答案:

答案 0 :(得分:2)

你必须引用argv中的一个项目,这是一个列表:

on run argv
    tell application "iTunes"
        duplicate track (first item of argv) to playlist "talks"
    end tell
end run
相关问题