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

发布于 2024-08-30 17:37:42 字数 2061 浏览 11 评论 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

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

感谢您的任何帮助!

The translation tool isn't able to translate this working code. I copied it out of a working script.

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

The code is taking a jpg image, converting it to a PICT file, and then reading the file minus the header (the first 512 bytes). Later in the script, albumArt will be added to an iTunes track.

I tried translating the code (minus the comments), but ASTranslate froze for a good 2 minutes before giving me this:

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

I have no clue how to make sense of this.

Thanks for any and all help!

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

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

发布评论

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

评论(1

陈独秀 2024-09-06 17:37:42

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

使用 ASDictionary 将标准添加字典导出为 HTML 并创建 objc-appscript 胶水 (SAGlue)。然后,您可以使用 -[SAApplication init] 创建一个新的 SAApplication 实例并向其发送 read 命令。

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

read is a Standard Additions command; ASTranslate doesn't support scripting additions, only scriptable applications, so you will have to translate it yourself.

Use ASDictionary to export the Standard Additions dictionary to HTML and create an objc-appscript glue (SAGlue). You can then use -[SAApplication init] to create a new SAApplication instance and send your read command to that.

Alternatively, you could skip Standard Additions completely and use NSData to read and slice the file and build the NSAppleEventDescriptor yourself.

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