I’d like to convert this tiny AppleScript to JavaScript :
tell application id “com.omnigroup.OmniGraffle6”
tell canvas of front window
make new shape at end of graphics with properties {size: {40.0, 30.0}, text: {size: 16, alignment: center, font: “HelveticaNeue”, text: “Toto”}, origin: {100.0, 100.0}}
end tell
end tell
Any idea ?
I’ve tried the following but this doesn’t work :
var app = Application(‘OmniGraffle’)
var t = app.Text({size:16, alignment:“center”, font:“HelveticaNeue”}, ‘Toto’)
var shape = app.Shape({size:[40,30], text:t, origin:[100,100]})
app.documents[0].canvases[0].graphics.push(shape)
I’ve also tried this but it doesn’t work either :
var t = app.Text({size:16, alignment:“center”, font:“HelveticaNeue”}, ‘Toto’)
var shape = app.Shape({size:[40,30], text:“Toto”, origin:[100,100]})
shape.text.size = 16
shape.text.font = “HelveticaNeue”
shape.text.alignment = “center”
app.documents[0].canvases[0].graphics.push(shape)
function run() {
'use strict'
var og = Application('OmniGraffle'),
ws = og.windows,
w = ws.length ? ws[0] : undefined, // document window ?
graphics = (w && w.id() !== -1 ? w.canvas.graphics : undefined);
if (graphics) {
var shp = og.Shape({
origin: [100, 100],
size: [150, 150]
}),
textRuns = (
// push new shape into graphics collection
graphics.push(shp),
// and get a reference to the attribute runs of the text
shp.text.attributeRuns
);
// Push a first attribute run
textRuns.push(og.Text({
size: 16,
alignment: "center",
color: [
0,
0,
0
],
font: "HelveticaNeue",
text: "Toto"
}));
// and then a second attribute run,
// with different formatting.
textRuns.push(og.Text({
size: 32,
color: [
1,
0,
0
],
font: "Courier",
text: "Toto"
}));
}
}