omniJS - Copy as JavaScript can create uncompilable code

Edit > Copy as JavaScript is currently producing uncompilable code in cases where any of the user data keys of a shape include spaces.

To make the code runnable, keys just need to be single or double quoted.

(I notice that Copy as Applescript is similarly producing unrunnable code in the same way)

For example, a shape with the following user data:

Might be copied as code including the uncompilable and unrunnable

g1.userData = { Share of total: "12%", Share of group: "40%" }

in lieu of:

g1.userData = { 'Share of total': "12%", 'Share of group': "40%" }

or

g1.userData = { "Share of total": "12%", "Share of group": "40%" }

(The same problem is occurring with Edit > Copy As AppleScript)

User data keys and automation action strings are still unquoted (and thus not compilable or runnable) in 7.4.1 test (v179.11 r292770)

e.g.

var canvas = document.windows[0].selection.canvas
var g1 = canvas.newShape()
g1.automationAction = [com.complexpoint.OmniGraffle, toggle]
g1.text = "Topic"
g1.cornerRadius = 5
g1.textVerticalPadding = 0
g1.autosizing = TextAutosizing.Clip
g1.textSize = 10
g1.strokeType = null
g1.userData = { test data: "with space" }
g1.geometry = new Rect(357.50, 141.68, 90.00, 90.00)
g1.shadowColor = null
g1.strokeColor = null
g1.magnets = [new Point(0.00, 1.00), new Point(0.00, -1.00)]
g1.fontName = "Helvetica"

Thanks for reporting this! It’s now fixed on the trunk (for Mac v7.5 and iOS v3.2) as of r292844.

1 Like

I notice that in 7.5 test (v181.3 r293706)

Edit > Copy as > JS is still creating code which won’t immediately compile from multiline graphic notes, where it is inserting a literal linefeed rather than an escaped \n or \r

For example, see the last two lines of:

// Floating point values in this script may be rounded, resulting in minor visual differences from the original
var canvas = document.windows[0].selection.canvas;
var g1 = canvas.newShape();
g1.geometry = new Rect(76.21, 78.10, 83.59, 132.03);
g1.shapeVertices = [new Point(87.37, 210.13), new Point(84.62, 204.95), new Point(82.24, 199.59), new Point(80.23, 194.08), new Point(78.62, 188.45), new Point(77.41, 182.71), new Point(76.61, 176.90), new Point(76.21, 171.05), new Point(76.22, 165.19), new Point(76.65, 159.34), new Point(77.48, 153.54), new Point(78.71, 147.81), new Point(80.35, 142.18), new Point(82.37, 136.68), new Point(84.78, 131.33), new Point(87.55, 126.17), new Point(90.68, 121.21), new Point(94.15, 116.48), new Point(97.94, 112.01), new Point(102.04, 107.82), new Point(106.42, 103.92), new Point(111.06, 100.34), new Point(115.94, 97.09), new Point(121.04, 94.19), new Point(126.32, 91.66), new Point(131.78, 89.50), new Point(137.37, 87.73), new Point(134.68, 78.10), new Point(159.80, 94.67), new Point(145.41, 116.63), new Point(142.73, 107.00), new Point(138.48, 108.35), new Point(134.33, 109.99), new Point(130.31, 111.92), new Point(126.43, 114.12), new Point(122.72, 116.59), new Point(119.18, 119.32), new Point(115.85, 122.28), new Point(112.74, 125.47), new Point(109.85, 128.88), new Point(107.21, 132.47), new Point(104.83, 136.24), new Point(102.72, 140.17), new Point(100.89, 144.24), new Point(99.35, 148.43), new Point(98.10, 152.71), new Point(97.16, 157.07), new Point(96.53, 161.49), new Point(96.21, 165.94), new Point(96.20, 170.40), new Point(96.50, 174.85), new Point(97.11, 179.27), new Point(98.04, 183.63), new Point(99.26, 187.92), new Point(100.78, 192.11), new Point(102.60, 196.19), new Point(104.69, 200.13)];
g1.strokeColor = Color.RGB(0.520042725261311, 0.587548638132296, 0.790051117723354);
g1.notes = "From 240.0º
To 360.0º";