“未知物体”尝试从 pict 文件捕获图稿并将其嵌入轨道时出错
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.
Hope this helps.
快速猜测一下,Appscript 引用与 AppleScript 引用一样,使用 1 索引,而不是像 Python 列表那样使用零索引。因此,您可能需要编写:
it.current_track.artworks[1].data_.set(...)
(顺便说一句,原始脚本中额外的
get
命令是不必要,但在这种情况下无害。)对于 ASTranslate,如果您希望它实际将命令发送到应用程序和脚本添加并接收其结果,则需要启用“将事件发送到应用程序”复选框。通常,最好禁用此选项,以便在翻译
set
或delete
等潜在破坏性命令时不会发生任何不幸的事故,因此仅启用它如果您确实需要它,请小心运行时运行的代码。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
ordelete
, so only to enable it if you really need it, and be careful what code you run when you do.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.