0

Je ne peux pas comprendre comment traduire la AppleScript suivante dans JXA (JavaScript pour l'automatisation sous Mac OS X Yosemite):JXA & OmniGraffle

tell application id "com.omnigroup.OmniGraffle6" 
    tell canvas of front window 
     make new line at end of graphics with properties {point list:L, draws shadow:false} 
    end tell 
end tell 

Voici ce que j'ai essayé, mais cela ne fonctionne pas lors de l'exécution la dernière ligne avec l'erreur "Gestionnaire AppleEvent a échoué":

app = Application('OmniGraffle') 

pt1 = app.Point({x:1,y:2}) 
pt2 = app.Point({x:1,y:2}) 

L = [] 
L.push(pt1) 
L.push(pt2) 

line = app.Line({pointList:L}) 

app.documents[0].canvases[0].lines.push(line) 

Quelqu'un peut-il aider?

Merci, Aurelien

Répondre

1

objets graphiques (lignes, formes, ...) sont contenues dans la collection graphique. Ainsi, vous devez changer la dernière ligne

app.documents[0].canvases[0].graphics.push(line) 
0

Et un équivalent, mais par exemple un peu plus complet:

(function() { 
    'use strict'; 

    var og = Application("OmniGraffle"), 
     ds = og.documents, 
     d = ds.length ? ds[0] : null, 
     cnvs = d ? d.canvases : [], 
     cnv = cnvs.length ? cnvs[0] : null, 
     gs = cnv ? cnv.graphics : null; 

    return gs ? (
     gs.push(
      og.Line({ 
       pointList: [[72, 216], [216, 72]], 
       drawsShadow: true, 
       thickness: 3, 
       lineType: 'orthogonal', 
       strokeColor: [1.0, 0.0, 0.0], 
       headType: "FilledArrow" 
      }) 
     ) 
    ) : null; 

})();