“未知物体”尝试从 pict 文件捕获图稿并将其嵌入轨道时出错

发布于 2024-08-09 04:25:28 字数 634 浏览 9 评论 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 消息:未知对象

类似的 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 时抛出错误。

I'm trying to capture artwork from a pict file and embed it into a track on iTunes using python appscript.
I did something like this:

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:])

I get an error OSERROR: -1731
MESSAGE: Unknown object

Similar applescript code looks like this:

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

I tried using ASTranslate but it never instantiates the_artwork and then throws an error when there is a reference to the_artwork.

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

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

发布评论

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

评论(3

小瓶盖 2024-08-16 04:25:28

这是一个较旧的问题,但由于我现在在做同样的事情时遇到困难,我想我应该发布我的解决方案,以防其他人受益。

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()

希望这有帮助。

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.

心不设防 2024-08-16 04:25:28

快速猜测一下,Appscript 引用与 AppleScript 引用一样,使用 1 索引,而不是像 Python 列表那样使用零索引。因此,您可能需要编写:

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

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

对于 ASTranslate,如果您希望它实际将命令发送到应用程序和脚本添加并接收其结果,则需要启用“将事件发送到应用程序”复选框。通常,最好禁用此选项,以便在翻译 setdelete 等潜在破坏性命令时不会发生任何不幸的事故,因此仅启用它如果您确实需要它,请小心运行时运行的代码。

At a quick guess, Appscript references, like AppleScript references, use 1-indexing, not zero-indexing like Python lists. So you probably need to write:

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

(Incidentally, the extra get command in your original script is unnecessary, though harmless in this case.)

As for ASTranslate, you need to enable the 'Send events to app' checkbox if you want it to actually send commands to applications and scripting additions and receive their results. As a rule, it's best to disable this option so that you don't have any unfortunate accidents when translating potentially destructive commands such as set or delete, so only to enable it if you really need it, and be careful what code you run when you do.

━╋う一瞬間旳綻放 2024-08-16 04:25:28

read 命令是脚本添加的一部分,ASTranslate 不会翻译成该命令。使用 ASDictionary 为脚本添加创建粘合剂,方法是单击“词典”菜单下的“选择已安装的脚本添加”,然后从列表中选择“脚本添加”。

The read command is part of Scripting Additions, which ASTranslate doesn't translate to. Use ASDictionary to create a glue for Scripting Additions, by clicking "Choose Installed Scripting Additions" Under the Dictionary menu, and then selecting "Scripting Additions" from the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文