This is a python function.
The javascript works fine on it's own, I can run it as a unique script, but this needs to fit into a bunch of other stuff that I've done.
I'm calling it via osascript, and I have another function that works perfectly fine.
And like I said, this block of code runs perfectly fine on it's own and does exactly what I want. I've tried it with #target illustrator and without, same result.
def _javascriptCreateCMYK(self):
js = '''
var SVGDoc = app.activeDocument;
var newDocPreset = new DocumentPreset;
newDocPreset.title = ("My Doc");
newDocPreset.width = (1920);
newDocPreset.height = (1080);
newDocPreset.units = RulerUnits.Pixels;
newDocPreset.colorMode = DocumentColorSpace.CMYK;
var finalDoc = app.documents.addDocument(DocumentColorSpace.CMYK, newDocPreset);
SVGDoc.activate();
SVGDoc.selectObjectsOnActiveArtboard();
app.copy();
finalDoc.activate();
app.paste();
SVGDoc.activate();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
finalDoc.activate();
'''
return js
And this is the Applescript that runs via a shell process.
script = '''
on run
tell application "%s"
set aiOpen to "%s" as POSIX file
activate
open aiOpen
activate
set js to "%s"
do javascript js
set newjs to "%s"
do javascript newjs
end tell
end run''' % (aiVersion, svgFile, js, newjs)