0

我正在尝试使用 applescript 在 iTune 中打开一个 .m3u 播放列表文件。我可以使用以下命令打开一个 iTune 播放列表文件:

#!/usr/bin/osascript
tell application "iTunes"
    play playlist "my playlist"
end tell

如何传递指向存在于任何位置的 .m3u 文件的完整路径?就像是:

#!/usr/bin/osascript
tell application "iTunes"
    play playlist "/path/to/folder/file.m3u"
end tell

谢谢。

4

2 回答 2

1

既然您在对问题的评论中指出您可以在 iTunes 中打开一个 m3u 播放列表并创建一个 iTunes 播放列表,那么我的建议是这样做。首先发出“打开”命令,在 iTunes 中创建播放列表后,再发出“播放播放列表”命令。

假设在 iTunes 中创建的播放列表的名称是 m3u 文件的文件名,那么这可能有效。另请注意,applescript 使用文件说明符,而不是文件的 posix 路径,因此我们使用“POSIX file”命令将您的 posix 路径转换为文件说明符。

我还没有尝试过,但这是我最好的猜测可能会起作用。祝你好运。

set posixPath to "/path/to/folder/fileName.m3u"
set fileSpecifier to POSIX file posixPath
tell application "iTunes"
    open fileSpecifier
    delay 1 -- delay however many seconds needed to allow the playlist to be created
    play playlist "fileName"
end tell

编辑:错误可能来自 iTunes 将您的 m3u 文件转换为 iTunes 播放列表时。m3u 文件中可能存在导致错误的内容。我不知道对此有何建议。

但是,错误也可能来自 POSIX 文件命令。这有时很敏感。因此,您可能会尝试解决这种可能性的一件事是将该命令强制转换为文本,然后在字符串路径之前使用单词“file”创建说明符。所以试试这个。如果错误来自 POSIX 文件命令,那么这应该可以修复它。

set posixPath to "/path/to/folder/fileName.m3u"
set fileSpecifier to (POSIX file posixPath) as text
tell application "iTunes"
    open file fileSpecifier
    delay 1 -- delay however many seconds needed to allow the playlist to be created
    play playlist "fileName"
end tell
于 2013-10-04T23:58:06.763 回答
0

你想使用命令行参数吗?

#!/usr/bin/osascript
tell application "iTunes"
    play playlist "$1/file.m3u"
end tell

你的命令行参数在哪里$1(第一个)

于 2013-10-04T17:22:11.177 回答