2010-04-29 15 views
0

L'outil de traduction n'est pas en mesure de traduire ce code de travail. Je l'ai copié d'un script de travail.Comment écrire l'applescript suivant dans Obj-C AppScript? ASTranslate était d'aucune aide = (

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 

Le code prend une image jpg, la conversion à un PICT fichier, puis en lisant le fichier moins l'en-tête (les 512 premiers octets.) Plus tard dans le script, albumArt sera ajouté à une piste iTunes

J'ai essayé de traduire le code (moins les commentaires), mais ASTranslate gelé pour un bon 2 minutes avant de me donner ceci:

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 

Je n'ai aucune idée de comment donner un sens à cela.

Merci pour toute aide!

Répondre

1

read est une commande Additions standard; ASTranslate ne supporte pas les ajouts de scripts, seulement les applications scriptables, donc vous devrez le traduire vous-même.

Utilisez ASDictionary pour exporter le dictionnaire Standard Additions vers HTML et créer une colle objc-appscript (SAGlue). Vous pouvez ensuite utiliser - [SAApplication init] pour créer une nouvelle instance SAApplication et envoyer votre commande read à cela. Sinon, vous pouvez ignorer complètement les additions standard et utiliser NSData pour lire et découper le fichier et construire le NSAppleEventDescriptor vous-même.