0

我正在尝试从 pict 文件中捕获艺术品,并使用 python appscript 将其嵌入到 iTunes 上的轨道中。我做了这样的事情:

imFile = open('/Users/kartikaiyer/temp.pict','r')
data = imFile.read()
it = app('iTunes')
sel = it.current_track.get()
sel.artworks[0].data_.set(data[513:])

我收到错误 OSERROR: -1731 MESSAGE: Unknown object

类似的 applescript 代码如下所示:

tell application "iTunes"
    set the_artwork to read (POSIX file "/Users/kartikaiyer/temp.pict") from 513 as picture
    set data of artwork 1 of current track to the_artwork
end tell

我尝试使用 ASTranslate 但它从不实例化the_artwork,然后在引用the_artwork.

4

3 回答 3

3

This is an older question, but since I was having trouble doing this same thing now, I thought I'd post my solution in case someone else might benefit.

selected = appscript.app('iTunes').selection.get()

for t in selected:
    myArt = open(/path/to/image.jpg,'r')
    data = myArt.read()
    t.artworks[1].data_.set(data) # no need to remove header but one-indexed as has said earlier
    myArt.close()

Hope this helps.

于 2010-12-27T16:46:22.957 回答
0

快速猜测一下,Appscript 引用,就像 AppleScript 引用一样,使用 1 索引,而不是像 Python 列表那样的零索引。所以你可能需要写:

it.current_track.artworks[1].data_.set(...)

(顺便说一句,get原始脚本中的额外命令是不必要的,尽管在这种情况下是无害的。)

至于 ASTranslate,如果您希望它实际向应用程序和脚本添加发送命令并接收其结果,则需要启用“向应用程序发送事件”复选框。作为一项规则,最好禁用此选项,这样您在翻译可能具有破坏性的命令(例如setor )时就不会发生任何不幸的事故delete,因此只有在您确实需要时才启用它,并注意您在执行时运行的代码.

于 2009-10-30T22:25:17.413 回答
0

read命令是脚本添加的一部分,ASTranslate 不会转换为。使用 ASDictionary 为 Scripting Additions 创建粘合,方法是单击 Dictionary 菜单下的“Choose Installed Scripting Additions”,然后从列表中选择“Scripting Additions”。

于 2010-05-07T09:22:12.760 回答