0

I'd like to place an image onto an Adobe Illustrator artboard using an image file selected in Finder. Can this be done using JavaScript?

var FINDER = Application("Finder");
FINDER.includeStandardAdditions = true;
var ImageA = FINDER.selection();

doc = app.activeDocument;

var adddoc = app.documents.add( null , 1275.59,898.58);
var placedItem = doc.placedItems.add();
placedItem.file = new File(ImageA);

CJK
  • 5,732
  • 1
  • 8
  • 26
Eason
  • 3
  • 3
  • That won’t work. Finder will return a list of object specifiers which only work in Finder. In AppleScript, you’d use `get … as alias` to coerce Finder objspecs to native file identifiers that can be passed to any application, but JXA doesn’t implement that. You can try to kludge around JXA’s numerous design flaws, or acknowledge it’s simply not fit for purpose and go back to using AppleScript, which is a lousy language but at least speaks Apple events right. – foo May 13 '19 at 09:12
  • You may also want to investigate Adobe’s own [embedded JavaScript](https://www.adobe.com/devnet/illustrator/scripting.html) (JSX) support. It’s not without its issues (`PARM` errors, anyone?) but it’s supported and has solid user help forums over on the Adobe website. As for general JavaScript scripting, get yourself a copy of Node.js. ([Adobe’s CEP](https://www.google.com/search?q="Adobe+Illustrator"+"CEP") uses Node, BTW.) If you’re really bold/desperate, there’s even [nodeautomation](https://www.npmjs.com/package/nodeautomation), but I don’t do free support so won’t recommend it. – foo May 13 '19 at 09:27

0 Answers0