HELP! Was working perfectly now it is giving me this error and doesn't seem to be going past the printing option. Code is below.
main.scpt
setposixIdPathto "/Applications/Adobe InDesign CC/Adobe InDesign CC.app"
do shell script "/Users/cdapice/Desktop/cryptoquip/getquip.sh"
delay 8
tellapplicationposixIdPath
activate
endtell
delay 8
setscripttoRunto ":Users:cdapice:Desktop:cryptoquip:Script.jsx" asalias
tellapplication "Adobe InDesign CC"
do scriptscripttoRunlanguagejavascript
endtell
delay 5
Adobe InDesign CC got an error: The property is not applicable in the current state." number 30615
Script.jsx
var myDocument = app.open(File("/Users/cdapice/Desktop/cryptoquip/NewCryptoquip.indt"), true);
//var myDocument = app.activeDocument;
var myPage = myDocument.pages.item(0);
var myTextFrame = myPage.textFrames.add();
//Place a text file in the text frame.
//Parameters for TextFrame.place():
//File as File object,
//[ShowingOptions as Boolean = False]
//You'll have to fill in your own file path.
myTextFrame.place(File("/Users/cdapice/Desktop/cryptoquip/quips.txt"));
//var myTextFrame = app.selection[0];
myTextFrame.parentStory.pointSize = 10;
var brkStory = myTextFrame.parentStory.contents;
var myPIs = myDocument.pageItems;
var destTextFrame = myPIs[6];
destTextFrame.parentStory.contents = brkStory;
firstChange();
myTextFrame.remove();
app.select(destTextFrame);
splitStory();
for (i = 0; i < myPIs.length; i++) {
if (myPIs[i].appliedObjectStyle.name == "puzzleBox") {
var newBoxStyle = myPIs[i].appliedObjectStyle;
secondChange(myPIs[i]);
myPIs[i].applyObjectStyle(newBoxStyle,true);
}
if(myPIs[i].appliedObjectStyle.name == "otherBox"){
var newBoxStyle = myPIs[i].appliedObjectStyle;
myPIs[i].applyObjectStyle(newBoxStyle,true);
}
}
Date.prototype.getMonthFormatted = function() {
var month = this.getMonth() + 1;
var formMonth = month < 10 ? '0' + month : month; // ('' + month) for string result
return formMonth.toString();
}
Date.prototype.getDayFormatted = function() {
var day = this.getDate();
var formDay = day < 10 ? '0' + day : day; // ('' + day) for string result
return formDay.toString();
}
var newdate = new Date();
var laterdate = new Date();
var dayofweek = newdate.getDay();
var offsetdays = 0;
switch(dayofweek) {
case 2:
offsetdays = 6;
break;
case 3:
offsetdays = 5;
break;
case 4:
offsetdays = 4;
break;
case 5:
offsetdays = 3;
break;
}
app.epsExportPreferences.appliedFlattenerPreset.convertAllStrokesToOutlines = true;
app.epsExportPreferences.appliedFlattenerPreset.convertAllTextToOutlines = true;
app.epsExportPreferences.appliedFlattenerPreset.rasterVectorBalance = 100;
//app.activeDocument.exportFile(ExportFormat.epsType, newFile, false);
for (i = 1; i < 7; i++) {
var curPage = i + "";
var x = i + (offsetdays - 1);
laterdate.setMonth(newdate.getMonth());
laterdate.setDate(newdate.getDate());
//alert(newdate);
//alert(x);
//alert(laterdate);
laterdate.setDate(newdate.getDate() + x);
//alert(laterdate);
var nameDate = laterdate.getMonthFormatted() + laterdate.getDayFormatted() + ".eps"
//alert(nameDate);
app.epsExportPreferences.pageRange = curPage;
var curFile = new File("/Users/cdapice/Desktop/cryptoquip/" + nameDate);
app.activeDocument.exportFile(ExportFormat.epsType, curFile, false);
}
var endDate = laterdate.getMonthFormatted() + laterdate.getDayFormatted();
var firstDate = new Date();
firstDate.setDate(newdate.getDate() + offsetdays);
var startDate = firstDate.getMonthFormatted() + firstDate.getDayFormatted();
var idFile = "cryptoquip_" + startDate + "_" + endDate + ".indd";
app.activeDocument.save(new File("/Users/cdapice/Desktop/cryptoquip/" + idFile));
with (app.activeDocument.printPreferences){
printer = "Advertising - Creative - Color Xerox";
copies = 1;
pageRange = "1-6";
paperSize = "US Letter";
paperHeight = "11 in";
paperWidth = "8.5 in";
printPageOrientation = PrintPageOrientation.landscape;
pagePosition = PagePositions.centered;
scaleHeight = 100;
scaleWidth = 100;
scaleMode = ScaleModes.scaleWidthHeight;
scaleProportional = true;
pageInformationMarks = true;
colorOutput = ColorOutputModes.COMPOSITE_CMYK;
}
app.activeDocument.print(false);
for(myCounter = app.documents.length; myCounter > 0; myCounter--){
app.documents.item(myCounter-1).close(SaveOptions.no);
}
function firstChange() {
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
app.findChangeTextOptions.caseSensitive = false;
app.findTextPreferences.findWhat = "^t";
app.changeTextPreferences.changeTo = "";
myDocument.changeText();
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = "^p^p";
app.changeTextPreferences.changeTo = "^p";
myDocument.changeText();
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = "^p";
app.changeTextPreferences.changeTo = "^R";
myDocument.changeText();
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
}
function secondChange(curFrame) {
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
app.findChangeTextOptions.caseSensitive = false;
app.findTextPreferences.findWhat = " ";
app.changeTextPreferences.changeTo = "|";
curFrame.changeText();
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = " ";
app.changeTextPreferences.changeTo = "";
curFrame.changeText();
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = "|";
app.changeTextPreferences.changeTo = " ";
curFrame.changeText();
app.findTextPreferences = NothingEnum.NOTHING;
app.changeTextPreferences = NothingEnum.NOTHING;
}
function splitStory(){
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if(app.documents.length != 0){
if(app.selection.length != 0){
//Get the first item in the selection.
var mySelection = app.selection[0];
//Process the selection. If text or a text frame is
//selected, do something; otherwise, do nothing.
switch(mySelection.constructor.name){
case "Text":
case "InsertionPoint":
case "Character":
case "Word":
case "Line":
case "TextStyleRange":
case "Paragraph":
case "TextColumn":
case "TextFrame":
//If the text frame is the only text frame in the story, do nothing.
if(mySelection.parentStory.textContainers.length > 1){
//Splitting the story is a two-step process: first, duplicate
//the text frames, second, delete the original text frames.
mySplitStory(mySelection.parentStory);
myRemoveFrames(mySelection.parentStory);
}
else{
alert("Please select a story containing more than one text frame and try again.");
}
break;
default:
alert("Please select some text or a text frame and try again.");
}
}
else{
alert("Please select some text or a text frame and try again.");
}
}
else{
alert("Please open a document and try again.");
}
}
function mySplitStory(myStory){
var myTextFrame;
//Duplicate each text frame in the story.
for(var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter --){
myTextFrame = myStory.textContainers[myCounter];
myTextFrame.duplicate();
}
}
function myRemoveFrames(myStory){
//Remove each text frame in the story. Iterate backwards to avoid invalid references.
for(var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter --){
myStory.textContainers[myCounter].remove();
}
}