Copy link to clipboard
Copied
I am a beginner at scripting, coding, and web design. I have been having questions regarding scripting.
I need help developing an Adobe Script that will 1)Automatically open a PDF file I have (created in Illustrator CC 2015)
2) Automatically change the name of two swatches, to new names I have
3) Save with same file name plus "_Z.PDF" at the end
4) Then close the file.
Copy link to clipboard
Copied
So you mean you've saved all your pdf file with "Preserve Illustrator Editing Capabilities" option checked on? You can start from here.
// 1)
var f = new File('path/to/filename.pdf');
var doc = app.open(f);
// 2)
doc.swatches.getByName('swatch_1').name = 'new_swatch_1';
doc.swatches.getByName('swatch_2').name = 'new_swatch_2';
// 3)
doc.saveAs(new File(f.fsName.replace(/\.pdf$/, '_Z.pdf')), new PDFSaveOptions());
// 4)
doc.close();
Copy link to clipboard
Copied
Thank you very much for your time and help. I tried running the script this way below but it says
there is still an error in the part : var doc = app.open(f);
What should I do about this? I have it underlined below too in bold italics.
function test()
{
// 1)
var thePath = "~/Desktop/";
var theFile = "test_swatch_change.pdf";
var f = new File(thePath + theFile);
var newFileName = theFile.replace(/\.pdf$/, "_Z.pdf");
var doc = app.open(f);
// 2)
doc.swatches.getByName('Kiss Cut').name = ('CutContourKiss-cut');
doc.swatches.getByName('Through Cut').name = ('CutContourThru-cut');
// 3)
var saveFile = new File(thePath + newFileName);
var saveOpts = new PDFSaveOptions();
doc.saveAs(saveFile, saveOpts);
// 4)
doc.close();
}
test();
Copy link to clipboard
Copied
Just works fine here.
try { var doc = app.open(f) } catch (e) { alert(e) }
what's the error info?
Copy link to clipboard
Copied
It says its not a function. I think its app.open that they are referring too.
Copy link to clipboard
Copied
Oh no, did you run it from ESTK and had not set target to illustrator?
Copy link to clipboard
Copied
yes, it wasnt going through