【发布时间】:2010-11-08 09:22:34
【问题描述】:
我正在编写一个用于 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 中执行脚本时遇到的错误是:
无法获得 {«class cFlT» id 16112 of «class cSrc» id 15982 of «class cSrc» id 65 of application "iTunes", ... 等的一些 «class cTrk»
现在,我真的不明白为什么它不起作用,尽管我想这一定与专辑中的项目是来自 iTunes 应用程序源的用户播放列表的文件轨道这一事实有关的“只是”轨道。有谁能帮帮我吗?
【问题讨论】:
-
aTrack来自哪里? -
如果您提供了一个工作示例会很好。见下面我的。
-
好的,抱歉。根据您的回复,我将示例简化为我困惑的本质。这有效:
tell application "iTunes" to set aTrack to some track,但这不起作用:tell application "iTunes" to set aTrack to some track as track。为什么? -
您评论中的问题代码可以更简单:
tell application "iTunes" to get some track as track。此示例的问题与问题中的不同。要将一个类强制转换为另一个类,应用程序必须定义一个coercion handler。显然,iTunes 没有定义从曲目到曲目的强制处理程序。这似乎并不少见:window 1 as window。
标签: applescript