0

翻译工具无法翻译此工作代码。我从工作脚本中复制了它。

set pathToTemp to (POSIX path of ((path to desktop) as string))

-- change jpg to pict
tell application "Image Events"
    try
        launch
            set albumArt to open file (pathToTemp & "albumart.jpg")
            save albumArt as PICT in file (pathToTemp & "albumart.pict")
            --the first 512 bytes are the PICT header, so it reads from byte 513
            --this is to allow the image to be added to an iTunes track later.
            set albumArt to (read file (pathToTemp & "albumart.pict") from 513 as picture)
        close
    end try
end tell

该代码正在获取 jpg 图像,将其转换为 PICT 文件,然后读取该文件减去标题(前 512 个字节)。稍后在脚本中,albumArt将添加到 iTunes 曲目中。

我尝试翻译代码(减去注释),但 ASTranslate 在给我这个之前冻结了 2 分钟:

Untranslated event 'earsffdr'

#import "IEGlue/IEGlue.h"
IEApplication *imageEvents = [IEApplication applicationWithName: @"Image Events"];
IELaunchCommand *cmd = [[imageEvents launch] ignoreReply];
id result = [cmd send];

#import "IEGlue/IEGlue.h"
IEApplication *imageEvents = [IEApplication applicationWithName: @"Image Events"];
IEReference *ref = [[imageEvents files] byName: @"/Users/Doom/Desktop/albumart.jpg"];
id result = [[ref open] send];

#import "IEGlue/IEGlue.h"
IEApplication *imageEvents = [IEApplication applicationWithName: @"Image Events"];
IEReference *ref = [[imageEvents images] byName: @"albumart.jpg"];
IESaveCommand *cmd = [[[ref save] in: [[imageEvents files] byName: @"/Users/Doom/Desktop/albumart.pict"]] as: [IEConstant PICT]];
id result = [cmd send];

'crdwrread'

Traceback (most recent call last):
  File "objcrenderer.pyc", line 283, in renderCommand
KeyError: 'crdwrread'


'cascrgdut'

Traceback (most recent call last):
  File "objcrenderer.pyc", line 283, in renderCommand
KeyError: 'cascrgdut'


'crdwrread'

Traceback (most recent call last):
  File "objcrenderer.pyc", line 283, in renderCommand
KeyError: 'crdwrread'


Untranslated event 'rdwrread'

OK

我不知道如何理解这一点。

感谢您的任何帮助!

4

1 回答 1

2

read是标准添加命令;ASTranslate 不支持脚本添加,仅支持可编写脚本的应用程序,因此您必须自己翻译。

使用 ASDictionary 将 Standard Additions 字典导出到 HTML 并创建 objc-appscript 胶水 (SAGlue)。然后,您可以使用 -[SAApplication init] 创建一个新的 SAApplication 实例并将您的read命令发送到该实例。

或者,您可以完全跳过标准添加并使用 NSData 读取和切片文件并自己构建 NSAppleEventDescriptor。

于 2010-04-30T20:40:17.740 回答