• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Scripting a PostScript File directly to folder no user interaction

Community Beginner ,
Jul 07, 2017 Jul 07, 2017

Copy link to clipboard

Copied

Hey guys hoping you might be able to point me in the right direction here. I'm a noob at scripting Illustrator and have been racking my brain over this script for a few days now.  What i would like to achieve is creating a script that will print a Postscript file to a designated folder with no user interaction. This folder will be on an external volume but just trying to get it to a folder on my desktop at this point... so this is what i started with initially :

var myDoc = app.activeDocument;

var options = new PrintOptions();

options.printPreset="PS_print";

myDoc.print(options);

Simple, and it works except that i still have to designate the folder in which the PostScript will be saved..  so i did some digging and came across this code Muppet Mark created on a thread called " Script: print to PostScript" here Re: Script: print to PostScript .  i ran it through ExtendScript and it executed once fine only thing i need to change is where the file is saving.   So i edited it and came up with this:

printPostScript();

function printPostScript(){

    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

   

    var docPath, docs, opts, psPath;

   

    jobOpts = new PrintJobOptions(); 

         

        opts = new PrintOptions(); 

          

        opts.printPreset = 'PS.print'; 

         

        opts.jobOptions =  jobOpts;

   

   

    docPath = decodeURI( app.activeDocument.fullName ); 

         

            psPath = new File( "~/Desktop/TEST" ); 

         

            jobOpts.file = File( psPath ); 

     

            app.activeDocument.print( opts ); 

     

            app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );

   

   

   

     app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS; 

   

   

}

problem is every time i use the userinteractionLevel command illustrator throws me an error  for the line where its supposed to execute the actual printing
"app.activeDocument.print( opts );"  Or at least im assuming the userinteractionLevel command is the culprit as Illustrator throws me the same error with the script   that i started with now when it didnt before.   If any of you guys could help me out here it would be appreciated!

Thanks

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 09, 2017 Jul 09, 2017

You assign new File() to a variable named psPath. It's nothing magic with that variable name. You could name it whatEverThatIsWhatIsStoredInMe; if you assign a file and not a folder the file is stored and not the folder.

So in effect you are storing a file in variable psPath. The name of the file is simply TEST and is saved directly on the Desktop. If you want a file in folder TEST then add a reasonable file name to the string.

"~/Desktop/TEST/myPostScriptFile.ps"

Or have a new look into the script

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 08, 2017 Jul 08, 2017

Copy link to clipboard

Copied

You mention twice that you get "an" error. Don't keep us in suspense! What error do you get?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2017 Jul 08, 2017

Copy link to clipboard

Copied

I guess it would help if gave the error huh lol sorry for the undue suspense.

It tells me an Illustrator error occurred: 20052('TN")Screen Shot 2017-07-08 at 10.54.49 AM.png

Then when i try and go back and run the initial code that was executing just fine before it will highlight the line
"myDoc.print(options);"

and just say the operation was cancelled. What am I doing incorrect ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2017 Jul 09, 2017

Copy link to clipboard

Copied

What am I doing incorrect ?

Hi,

hard to tell what is provoking the error.

At least you should give the file you are writing a decent name.

Currently you are writing a file that is named "TEST" without suffix.

I tested your code using one of my print presets and it was running as expected.

Illustrator CC v 17.1.0 on OS X 10.6.8

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2017 Jul 09, 2017

Copy link to clipboard

Copied

Hi Uwe !

Thanks for testing the code out for me. Its nice to know the code is executing, maybe it just something w/ my personal computer we're running the same version of illustrator. 

Don't pay attention to the "TEST" name that's just me being a scripting noob and trying to figure out how to write the PostScript file to the folder located on my desktop named "TEST", the file name is actually "0904USCPWU_Franky_WHT-CRD_CF_SEPS.eps". 

i thought theses lines of code

docPath = decodeURI( app.activeDocument.fullName ); 

         

            psPath = new File( "~/Desktop/TEST" ); 

got the actual file name then wrote it to that location. how should i be doing this ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2017 Jul 09, 2017

Copy link to clipboard

Copied

You assign new File() to a variable named psPath. It's nothing magic with that variable name. You could name it whatEverThatIsWhatIsStoredInMe; if you assign a file and not a folder the file is stored and not the folder.

So in effect you are storing a file in variable psPath. The name of the file is simply TEST and is saved directly on the Desktop. If you want a file in folder TEST then add a reasonable file name to the string.

"~/Desktop/TEST/myPostScriptFile.ps"

Or have a new look into the script where you copied the code from.

There a file is done by using the AI file name. But in a different line of code you did not copy over. The suffix ai is replaced by ps using a regular expression.

If you want to use the name of your active document you could do something like that where a regular expression is used to replace the .ai at the end of the name with .ps.

Here an example:

psPath = new File( "~/Desktop/TEST/"+app.activeDocument.name.replace(/\.ai$/,".ps") );

Now you are using TEST as a folder name plus the name of the active document as base name for the file.

ps stands for PostScript. Not for EPS ( Encapsulated PostScript ).

That's a difference! If you want an EPS file you have to use Illustrator's save feature.

Regards,
Uwe

//EDITED

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2017 Jul 09, 2017

Copy link to clipboard

Copied

LATEST

Thanks for the assist and insight Uwe!

your explanation and example "psPath = new File( "~/Desktop/TEST/"+app.activeDocument.name.replace(/\.ai$/,".ps") ); "

made it execute perfectly.


Below is the final code if anyone is interested:

function printPostScript(){

    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

   

    var docPath, opts, psPath;

   

    jobOpts = new PrintJobOptions(); 

         

        opts = new PrintOptions(); 

          

        opts.printPreset = 'PS.print'; 

         

        opts.jobOptions =  jobOpts;

   

   

    docPath = decodeURI( app.activeDocument.fullName ); 

         

    psPath = new File( "~/Desktop/TEST/"+app.activeDocument.name.replace(/\.eps$/,".ps") );

         

    jobOpts.file = File( psPath ); 

     

    app.activeDocument.print( opts ); 

     

    app.activeDocument.close( SaveOptions.SAVECHANGES );

   

   

   

     app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS; 

   

   

}

printPostScript();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines