Hack: Get/set lineType from JS, bypassing broken enum

While the non-conformant OGLT (lineType) enum in the OG 6.4.1 (v167.4 r248283) build breaks the reading and setting of OmniGraffle lines through Apple’s JavaScript for Automation, we can use a slow and fairly clumsy interim hack to read or set the type of line (calling a line of AppleScript (through a shell script) from JavaScript).

For example, to experiment with setting and checking the type of a selected line from JavaScript for Automation, paste the whole of the following script into Script Editor, and set the language selector at top left to JavaScript.

(function () {
	'use strict';


	var a = Application.currentApplication(),
		sa = (a.includeStandardAdditions = true, a);


	// GET OR SET LINE-TYPE OF LINE (specified by its id)
	function lineType(id, typeName) {
		var boolSet = typeName && [
			'straight', 'orthogonal', 'curved', 'bezier'
		].indexOf(typeName) !== -1;

		return sa.doShellScript([
			"osascript -e 'tell application \"OmniGraffle\" to",
			boolSet ? "set" : "",
			"line type of graphic id",
			id,
			"of canvas of front window",
			boolSet ? "to " + typeName : "",
			"'"
		].join(' '));
	}


	// EXAMPLE - CHANGE (AND THEN CHECK) THE LINE TYPE OF THE SELECTED LINE

	var og = Application('OmniGraffle'),
		ws = og.windows.whose({
			_not: [{
				document: null
			}]
		}),
		w = ws.length ? ws[0] : undefined,
		slns = w ? w.selection() : [];



	if (slns.length) {

		// ID OF SELECTED LINE
		var selectedGraphic = slns[0],
			id = selectedGraphic.id();


		if (selectedGraphic.class() === 'line') {

			// SET LINE TYPE (2 arguments) of selected line
			lineType(id, 'orthogonal');


			// GET LINE TYPE (1 argument only) of selected line
			return lineType(id);
		}
	}

})();