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;
}();
_;