使用 AppleScript 选择 iTunes 中的所有曲目
我有一个非常基本的 AppleScript,我试图在我的 Mac 上运行它,以删除 iTunes 中所有歌曲的评级:
tell application "iTunes"
set sel to every track in library playlist
repeat with i from 1 to the count of sel
set rating of track i in sel to 0
end repeat
end tell
我以前从未用 AppleScript 编写过任何内容,但我想尝试一下(因为它应该如此直观)。不幸的是,当我尝试运行脚本时收到此错误:
error "Can’t get every track of library playlist." number -1728
from every «class cTrk» of «class cLiP»
此错误是什么?是否有其他方法可以在 iTunes 中选择曲目?感谢您的任何帮助。
I have this very basic AppleScript which I'm trying to run on my Mac to remove the ratings from all my songs in iTunes:
tell application "iTunes"
set sel to every track in library playlist
repeat with i from 1 to the count of sel
set rating of track i in sel to 0
end repeat
end tell
I've never written anything in AppleScript before, but thought I'd give it a shot (since it's supposed to be so intuitive). Unfortunately, I receive this error when I try to run the script:
error "Can’t get every track of library playlist." number -1728
from every «class cTrk» of «class cLiP»
What is this error? Is there an alternate way of selecting the tracks in iTunes? Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不完全知道为什么,但答案是库播放列表实际上并不包含曲目。我知道这很奇怪,但由于您只想在每个轨道上运行它,所以有一个更简单的解决方案。而不是
库的每个轨道
,只需使用每个轨道
;这实际上将获得应用程序中的每个曲目,这正是您想要做的。经过一些其他简化,这变成了tell application "iTunes" to ...
语法就像一个普通的tell
块,但它只有一个语句长,并且不不要接受结束告诉
。您可以立即对列表中的每个条目自动运行set
命令,这就是您所需要的。一般来说,你很少需要通过索引进行枚举;例如,对于更接近您的解决方案的东西,有等效的这可以避免索引,并且也可能会更快(尽管单行可能是最快的,如果存在差异)。
I don't entirely know why, but the answer is that the library playlist doesn't actually contain tracks. Strange, I know, but since you just want to run this over every track, there's an even simpler solution. Rather than
every track of library
, just useevery track
; this will get literally every track in the application, which is what you're trying to do. And with a few other simplifications, this becomesThe
tell application "iTunes" to ...
syntax is just like an ordinarytell
block, but it's only one statement long and doesn't take anend tell
. And you can automatically run theset
command over every entry in the list at once, so that's all you need. In general, you rarely need to enumerate via indices; for instance, for something closer to your solution, there's the equivalentThis avoids the indexing, and will also likely be faster (though the one-liner will probably be fastest, if there's a difference).
您被误导了:AppleScript 不是很直观,主要是因为它观察到的大部分行为是由每个应用程序对其对象模型的实现决定的。虽然它可能非常强大,但您通常只需进行试验,直到找到适合特定应用程序的正确咒语。
在这种情况下,您需要选择播放列表的第一项。请注意差异:
但您可能想要做的更像是这样:
如果您有一个大型库,您可能想首先尝试较小的播放列表,例如,在测试播放列表中选择一个曲目,然后替换
在当前播放列表
中的repeat
语句中。You've been misinformed: AppleScript is not very intuitive, primarily because so much of its observed behavior is determined by each application's implementation of its object model. While it can be very powerful, you often just have to experiment until you find the right incantations that work for a particular application.
In this case, you need to select the first item of playlists. Note the differences:
But what you probably want to do is something more like this:
If you have a large library, you might want to first experiment with a smaller playlist, for instance, select a track in a test playlist and then substitute
in current playlist
in therepeat
statement.