Applescript:通过文件系统路径在播放列表中查找曲目

发布于 2024-12-21 08:57:34 字数 813 浏览 2 评论 0原文

无法根据文件系统路径(位置)从播放列表中选择曲目。见下文。

我在每个命令的结果之前放置了箭头。

在第一行中,我成功地从播放列表“Testing”中找到了流派“R&B”的第一首曲目。

为什么第四行不起作用?看起来我正在做与第 1 行相同的事情,仅按文件系统位置而不是按流派搜索。

还有另一种方法可以做到这一点吗?

tell application "iTunes"....
  set t to first track of playlist "Testing" whose genre is "R&B"
   --> file track id 18476 of user playlist id 18414 of source id 72 of application "iTunes"

  set l to location of track 1 of playlist "Testing"
   --> alias "Lion:Users:cworth:Desktop:a.mp3"

  set f to POSIX file "/Users/cworth/Desktop/a.mp3" as alias
   --> alias "Lion:Users:cworth:Desktop:a.mp3"

  set tt to first track of playlist "Testing" whose location is f
   --> error "iTunes got an error: A descriptor type mismatch occurred." number -10001 to item
...end tell

Can't pick a track from a playlist based on it's file system path (location). See below.

I put arrows before the result of each command.

In the first line, I successfully find the first track from the playlist "Testing" with genre "R&B".

Why doesn't the fourth line work ? It looks like I am doing the same as line 1 only searching by file-system location instead of by genre.

Is there another way to do this ?

tell application "iTunes"....
  set t to first track of playlist "Testing" whose genre is "R&B"
   --> file track id 18476 of user playlist id 18414 of source id 72 of application "iTunes"

  set l to location of track 1 of playlist "Testing"
   --> alias "Lion:Users:cworth:Desktop:a.mp3"

  set f to POSIX file "/Users/cworth/Desktop/a.mp3" as alias
   --> alias "Lion:Users:cworth:Desktop:a.mp3"

  set tt to first track of playlist "Testing" whose location is f
   --> error "iTunes got an error: A descriptor type mismatch occurred." number -10001 to item
...end tell

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人事已非 2024-12-28 08:57:34

研究了 Applescript 并让它在曲目上使用显式循环:(见下文)

为什么上面的示例不起作用的一个可能的解释是“播放列表“测试”的第一首曲目的位置是...”返回对象说明符列表(例如,播放列表“测试”的第一首曲目的位置等)而不是实际位置列表 - 即缺少的是返回您在重复循环内看到的实际位置的“get”命令以下。这也许可以解释描述符类型不匹配的原因?我没有 Applescript 专业知识或动力继续前进,既然我已经让它工作了,但我很高兴它是这样!

tell application "iTunes"
set f to POSIX file "/Users/cworth/Music/04 It's A Man's, Man's, Man's World.mp3"
set a to f as alias
set z to missing value
repeat with tr in tracks of playlist "Testing"
    set ll to get location of tr
    if ll is a then set z to ll
end repeat
end tell
log z

Studied up on Applescript and got it working with an explicit loop over the tracks: (see below)

A possible explanation for why the example above doesn't work is that the 'first track of playlist "Testing" whose location is...' returns a list of object specifiers (e.g. location of first track of playlist "Testing", etc.) instead of a list of actual locations - i.e. what's missing is the "get" command that returns the actual locations that you see inside the repeat loop below. That would explain the descriptor type mismatch, maybe ? I don't have the Applescript expertise or motivation to go any further, now that I've got it working, but I'm glad that it is!

tell application "iTunes"
set f to POSIX file "/Users/cworth/Music/04 It's A Man's, Man's, Man's World.mp3"
set a to f as alias
set z to missing value
repeat with tr in tracks of playlist "Testing"
    set ll to get location of tr
    if ll is a then set z to ll
end repeat
end tell
log z
隔岸观火 2024-12-28 08:57:34

非常迟来的回复。我认为问题在于 track 类型没有 location 属性,但 file track 类型有。尝试搜索 file track 实例列表而不是所有 track 实例:

tell application "Music"
    set f to POSIX file "/Users/cworth/Music/04 It's A Man's, Man's, Man's World.mp3"
    set res to first file track whose location is f
    return res
end tell

Very belated reply. I believe the issue is that the track type does not have a location attribute, but the type file track does. Try searching the list of file track instances rather than all track instances:

tell application "Music"
    set f to POSIX file "/Users/cworth/Music/04 It's A Man's, Man's, Man's World.mp3"
    set res to first file track whose location is f
    return res
end tell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文