Come faccio a scrivere il seguente AppleScript in Obj-C AppScript? ASTranslate era di nessun aiuto = (
-
02-10-2019 - |
Domanda
Lo strumento di traduzione non è in grado di tradurre questo codice di lavoro. Ho copiato da uno script di lavoro.
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
Il codice sta prendendo un'immagine jpg, convertendolo in un file PICT, e quindi la lettura del file meno l'intestazione (i primi 512 byte). Più tardi nello script, albumArt
verrà aggiunto a un iTunes traccia.
Ho provato a tradurre il codice (meno i commenti), ma ASTranslate congelato per un buon 2 minuti prima di avermi dato questa:
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
Non ho idea di come rendere il senso di questo.
Grazie per qualsiasi aiuto!
Soluzione
read
è un comando standard integrazioni; ASTranslate non supporta le aggiunte di scripting, solo le applicazioni script, in modo da avere a tradurre da soli.
Usa ASDictionary per esportare il dizionario standard aggiunte in HTML e creare una colla objc-appscript (SAGlue). È quindi possibile utilizzare - [SAApplication init] per creare una nuova istanza SAApplication e inviare il vostro comando read
a quello.
In alternativa, è possibile saltare Aggiunte standard completamente e utilizzare NSData per leggere e tagliare il file e costruire il NSAppleEventDescriptor da soli.