错误:无法获取某些“类” {«类», «类», ...}
我正在编写一个在 iTunes 中使用的 Applescript,其中有时我想从曲目列表中选择任何曲目,但我期望它的工作方式出现错误。代码如下:
tell application "iTunes"
set thePlaylist to the first playlist whose name is "Missing track count"
-- ...
-- populate a list of strings: albumList
-- ...
repeat with albumName in the albumList
set theAlbum to (the tracks of thePlaylist whose album is albumName)
display dialog "Found " & (count theAlbum) & " tracks in the album"
set aTrack to some track of theAlbum -- ERROR OCCURS HERE
end repeat
end tell
当我从 iTunes 中执行脚本时出现的错误是:
无法获取应用程序“iTunes”的“class cSrc” id 65 的“class cUsP” id 15982 的“class cFlT” id 16112 的“class cTrk”,...等}
现在,我真的不明白为什么它不起作用,尽管我猜想这一定与专辑中的项目是来自 iTunes 应用程序源的用户播放列表中的文件曲目而不是“只是”曲目有关。有人可以帮我吗?
I'm writing an Applescript for use in iTunes in which at some point I want to select any track from a list of tracks, but the way I expected it to work gives an error. Here's the code:
tell application "iTunes"
set thePlaylist to the first playlist whose name is "Missing track count"
-- ...
-- populate a list of strings: albumList
-- ...
repeat with albumName in the albumList
set theAlbum to (the tracks of thePlaylist whose album is albumName)
display dialog "Found " & (count theAlbum) & " tracks in the album"
set aTrack to some track of theAlbum -- ERROR OCCURS HERE
end repeat
end tell
The error I get when I execute the script from within iTunes is:
Can't get some «class cTrk» of {«class cFlT» id 16112 of «class cUsP» id 15982 of «class cSrc» id 65 of application "iTunes", ... etc}
Now, I don't really see why it doesn't work, although I guess it must have something to do with the fact that the items in theAlbum are file tracks from a user playlist from the source from the iTunes application instead of 'just' tracks. Can anyone help me out here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在此示例中,我使用
some item
而不是some track
,效果很好。结果
由于您示例中的所有项目都继承自 track,所以我不知道为什么它不起作用,但它不起作用。
In this example I use
some item
instead ofsome track
, which works OK.results in
Since all the items in your example inherit from track, I don't know why it doesn't work, but it doesn't.
theAlbum
是一个列表,而不是播放列表,因此它没有轨道元素;它只有 项目。关于列表的文档,其中指出“您还可以按类别引用索引列表项”。不完整,因此具有误导性。看来您只能对内置类执行此操作。据我所知,原因如下:
对象说明符 (2) 是 基于键值编码。 说明符可以标识属性(对象属性或一对一关系)或元素(一对多关系)。在示例中,我们正在处理元素。要处理元素,底层 Objective-C 类必须实现 集合访问器模式。也就是说,它必须 至少实现
-
或-countOf
和-objectInAtIndex:
(当然,它可以实现所有这些)。列表类对一定数量的 Applescript 类执行此操作(如果您查看列表类的 ObjC 源代码,您会发现类似countOfApplication
和-objectInNumberAtIndex:
的方法)。可以想象,它可以使用适当的-doesNotRecognizeSelector:
处理程序支持任意元素对象说明符,但列表似乎并未以这种方式实现。由于列表没有-track
、-countOfTrack
或-objectInTrackAtIndex:
处理程序,因此它们无法处理诸如“< code>trackList 的第一首曲目”。theAlbum
is a list, not a playlist, so it doesn't have track elements; it only has items.The documentation on lists, where it states "You can also refer to indexed list items by class." is incomplete and thus misleading. It seems you can only do this with to built-in classes. From what I can glean, here's why:
Object specifiers (2) are based on key-value coding. A specifier might identify a property (an object attribute or a to-one relationship) or element (a to-many relationship). In the example, we're dealing with elements. To handle elements, the underlying Objective-C class must implement a collection accessor pattern. That is, it must implement at least
-<key>
, or-countOf<Key>
and-objectIn<Key>AtIndex:
(it can, of course, implement all of them). The list class does this for a set number of Applescript classes (if you peeked at the ObjC source for the list class, you'd find methods likecountOfApplication
and-objectInNumberAtIndex:
). It could conceivably support arbitrary element object specifiers with an appropriate-doesNotRecognizeSelector:
handler, but lists don't appear to have been implemented this way. Since lists don't have-track
,-countOfTrack
or-objectInTrackAtIndex:
handlers, they can't deal with a specifier such as "first track of trackList
".