URL.choose Error Copied Code from Omni-Automation?


#1

Ok… I’ve been using OmniGraffle for a while, but have just started really working on learning how to create my own actions… so absolutely possible I’m missing something obvious ;)

When I run the script below (section copied from Omni-Automation indicated in comments) I am getting the following error:

TypeError: URL.choose is not a function. (In 'URL.choose(['public.image'])',  'URL.choose' is undefined)

My script:

var _ = function(){
	var action = new PlugIn.Action(function(selection){
		cnvs = document.windows[0].selection.canvas
		// FOLLOWING COPIED FROM:
		//https://www.omni-automation.com/shared/url-choose.html
		/* ERROR TEXT:
		TypeError: URL.choose is not a function. (In 'URL.choose(['public.image'])', 
		'URL.choose' is undefined) */
		imageURL = URL.choose(['public.image'])
		if (imageURL == null){throw new Error('user cancelled')}
		urlString = imageURL.string
		var imageFileName = urlString.substr(urlString.lastIndexOf('/') + 1)
		imageFileName = decodeURIComponent(imageFileName)
		imageURL.fetch(function(data){
			aGraphic = cnvs.newShape()
			aGraphic.strokeThickness = 0
			aGraphic.shadowColor = null
			aGraphic.fillColor = null
			aGraphic.image = addImage(data)
			aGraphic.name = imageFileName
			imageSize = aGraphic.image.originalSize
			imgX = imageSize.width
			imgY = imageSize.height
			aGraphic.geometry = new Rect(aGraphic.geometry.x, aGraphic.geometry.y, imgX, imgY)
		// END COPIED SECTION
			aGraphic.notes = "Original image file location:" + "\n" + urlString + "\n" + "\n" + "Original dimensions:" + "\n" + imgX +"w X " + imgY + "h"
			document.windows[0].selection.view.select([aGraphic])
		})
		
	});
	action.validate = function(selection){
		// validation code
		// selection options: canvas, document, graphics, lines, solids, view


		if(document.windows[0].selection.canvas != null){
			return true
		} else {
			return false
		}
	};
	return action;
}();
_;

#2

I’m able to run those sample scripts from the Console without error in macOS 10.14 OmniGraffle 7.9 Pro.

When you run this line in the console, do you get an error?
chosenFile = URL.choose(['public.image'])

Thanks,
Lanette