我如何在Obj-C AppScript中编写以下AppleScript? ASTranslate没有帮助=(

时间:2010-04-29 11:52:15

标签: objective-c cocoa image-processing appscript

翻译工具无法翻译此工作代码。我把它从工作脚本中删除了。

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

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

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

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

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

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