如何在OBJ-C AppScript中编写以下AppleScript? astranslate没有帮助=(
-
02-10-2019 - |
题
翻译工具无法翻译此工作代码。我从工作脚本中复制了它。
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
我不知道如何理解这一点。
感谢您的任何帮助!
解决方案
read
是标准加法命令; Astranslate不支持脚本添加,只有可脚本的应用程序,因此您必须自己翻译。
使用Asdictionary将标准添加字典导出到HTML并创建OBJC-Appscript胶(Saglue)。然后,您可以使用 - [Sapplication Init]创建一个新的Sapplication实例并发送您的 read
命令。
另外,您可以完全跳过标准添加,并使用NSDATA来读取和切片文件并亲自构建NSAPPLEEVENTDESCRIPTOR。
不隶属于 StackOverflow