Thread View: adobe.scripting.indesign
10 messages
10 total messages
Started by John_Kallios
Wed, 25 Mar 2009 05:14
JS CS4 Print to postscript
Author: John_Kallios
Date: Wed, 25 Mar 2009 05:14
Date: Wed, 25 Mar 2009 05:14
23 lines
1435 bytes
1435 bytes
Part 2 of trying to print to postscript.
Current:
function mySnippet(){
//<fragment>
//Prints the active document using the specified printer preset.
var myDocument = app.documents.item(0);
myDocument.print(true, app.printerPresets.item("ps"));
var printFile = "/Users/john/Desktop/PS_Hotfolder/In/" + myDocument.name;
if(printFile.indexOf(".indd")!=-1){
var myRegularExpression = /.indd/gi
printFile = printFile.replace(myRegularExpression, ".ps");
}
//alert(printFile);
I have verified the preset is activated correctly. With the alert, it has returned the file name I am after.
Where I'm stuck: The next window where to save the postscript file fails for me. No postscript is created nor does it enter the name in the save dialogue for me.
Question: What is the code line to call upon the save dialogue so I may enter the save name?
Thanks in advance
Re: JS CS4 Print to postscript
Author: Peter Kahrel
Date: Wed, 25 Mar 2009 11:11
Date: Wed, 25 Mar 2009 11:11
30 lines
1873 bytes
1873 bytes
John,
For me this works fine:
myDocument.print(true, app.printerPresets.item("ps"))
Running this line shows the Print then the Print to File dialog, the same that you get when you print from the interface. You can also use this:
myDocument.print(false, app.printerPresets.item("ps"))
Now you get just a small Print to File dialog in which you can enter the name of the file. Maybe give that one a try and see what happens. If you still don't see the dialog you expect, do you see any at all? Could it be that you disabled dialogs using some userInteraction setting? To rule that out, run this one-liner:
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
and try again.
As to the file name you construct for the PS file, there's no point doing that because you can't use it in the script. As far as I can see, you have to enter the file name manually in the dialog. This is unlike exporting to EPS, PDF, etc., where you can say something like "export myDoc to PDF using filename X and preset Y". In other words, you can't say "print myDoc as PS using filename X and preset Y". You have to go through the dialog, and you have to type the name.
Hope this helps.
Peter
Re: JS CS4 Print to postscript
Author: Kasyan_Servetsky
Date: Wed, 25 Mar 2009 14:21
Date: Wed, 25 Mar 2009 14:21
14 lines
1336 bytes
1336 bytes
As to the file name you construct for the PS file, there's no point doing
that because you can't use it in the script... In other words, you can't
say "print myDoc as PS using filename X and preset Y". You have to go
through the dialog, and you have to type the name.
You can use PrintPreference's printFile property to set the name of the PS-file and you can use activePrinterPreset to choose a printer preset in script. I do it in my script that exports each page to a separate PS-file and names each file in the following form:
Page number + "_Magazine name_" + Issue number + ".ps"
e.g. 012_business_843.ps
<http://www.kasyan.ho.com.ua/downloads/PrintEachPageAsPs%20v3.6.zip>
Re: JS CS4 Print to postscript
Author: John_Kallios
Date: Wed, 25 Mar 2009 14:23
Date: Wed, 25 Mar 2009 14:23
35 lines
2091 bytes
2091 bytes
Hi Peter, When I turn the print line to true, the print dialog appears and correctly targets my preset. Clicking save brings up the second save dialog. When it is false, the second dialog does not appear. I will try the script to ensure no user action was turned off. The scripting guide mentions when setting print preferences: (and it is commented out) //If the printer property is set to Printer.postScript file, then the printFile property contains the file path to the output file. //printFile = "/c/test.ps" This led me believe that I could write to the 2nd dialog. However, if I cannot, I will initiate phase 2. While sounding official, it just means I will convert my department from distilling ps to pdf to exporting to pdf. I estimated 10 more jobs prepped per day with printing to postscript, I should be able to get 15 more with exporting. You be seeing a new questing, in a new topic, soon after I bang my head against the wall: "How to get the full document path of the file and export the pdf one level up and back into anther sub folder. Plus, gleaming what the other subfolder's name is." Example: File name: "jobnumber"+"other text" ~document path/working move up path to ~document path move into subfolder ~document path/"jobnumber"+"pdf" and save the file with the document name. I'll need to throw in an if statement to check if the file ever was saved to begin with. Now I'm thinking out loud. Please forgive me.
Re: JS CS4 Print to postscript
Author: John_Kallios
Date: Wed, 25 Mar 2009 14:30
Date: Wed, 25 Mar 2009 14:30
5 lines
737 bytes
737 bytes
Thank you Kasyan, I will be able to try later this morning. First order of business is to get my son off to school. Cheers.
Re: JS CS4 Print to postscript
Author: Kasyan_Servetsky
Date: Wed, 25 Mar 2009 15:30
Date: Wed, 25 Mar 2009 15:30
37 lines
1677 bytes
1677 bytes
Hi John,
I'm not sure if this is exactly what you want. I assume that you want to save a ps-file to 'PS_Files' folder which is one level up relative to the folder where the current InDesign's file resides. If such folder doesn't exist it will be created after confirmation.
Kasyan
var myDoc = app.activeDocument;
var myPrintPrefs = myDoc.printPreferences;
if (app.printerPresets.item("ps") == null) {
alert("Printer preset \"ps\" is not installed.");
exit();
}
else {
myPrintPrefs.activePrinterPreset = app.printerPresets.item("ps");
}
var myDocPath = myDoc.filePath;
var myFileName = myDoc.name.replace(/\.indd$/i, "") + ".ps";
var myPsFolder = new Folder(myDocPath.parent.fsName + "/PS_Files");
if (!myPsFolder.exists) {
var myConfirm = confirm("Folder \"PS_Files\" doesn't exists. Do you wan to create it?");
if (myConfirm) {
myPsFolder.create();
}
else {
exit();
}
}
var myFile = new File(myPsFolder + "/" + myFileName);
myPrintPrefs.printFile = myFile;
myDoc.print(false);
alert("All done!");
Re: JS CS4 Print to postscript
Author: Peter Kahrel
Date: Wed, 25 Mar 2009 15:38
Date: Wed, 25 Mar 2009 15:38
10 lines
743 bytes
743 bytes
You can use PrintPreference's printFile property ...
Well, that shows I've not used that before.
Peter
Re: JS CS4 Print to postscript
Author: John_Kallios
Date: Wed, 25 Mar 2009 17:13
Date: Wed, 25 Mar 2009 17:13
7 lines
1001 bytes
1001 bytes
Thank you Peter and Kasyan, You are both a big help. Thank you very much Kasyan for the code. You do know I will take credit at my work? Actually, I am very big on given credit where due. :) For closure, I respond back when I have a completed script. If you could not guess, I'm a newbie uninitiated. <-- Dave Saunders labeled me
Re: JS CS4 Print to postscript
Author: John_Kallios
Date: Thu, 26 Mar 2009 16:33
Date: Thu, 26 Mar 2009 16:33
9 lines
851 bytes
851 bytes
Semi-closure: Thanks again Kasyan for the script. I'm printing PS to the folder I want to. Follow up question for all. On a Mac, what is the string of text to point to the desktop regardless of the username logged in? Thanks, John
Re: JS CS4 Print to postscript
Author: Kasyan_Servetsky
Date: Thu, 26 Mar 2009 17:18
Date: Thu, 26 Mar 2009 17:18
5 lines
642 bytes
642 bytes
var myFolder = Folder ("~/Desktop");
both for Mac & Pc
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads