@Alex – you can add a pageBreak special character at the end of a story like that:
//Adding a pageBreak at the end of a story: var myStory = app.documents.stories; myStory.insertionPoints.lastItem().contents = SpecialCharacters.pageBreak;
Just tested that in InDesign CS5.5.
Thank you, you're right. What I do not understand, though, is the difference between "=" and "+=" at this point. With the concatenation operator ID does not create a page break but inserts the code for it instead in the text.
A 'contents' item may be a SpecialCharacters enumeration -- a number --, or a text string. The way you refer to the existing item, you might get either: if that last character happens to be representable as one of the Special Characters, you get a number; if not, you get a string.
So what happens, using the '+' operator and a number on something of which you are not sure what type it is?
2. If you get a number back, you are in even more trouble! Suppose there already happened to be a "Special Character" enumerated value on that last position -- say, an en-dash ("SpecialCharacters.EN_DASH"). Its numerical representation -- which gets returned if you query it -- is 1397059140. Guess what happens if you use '+=' to ADD the number 1397778242 (your page break, remember) to it? You get the value 2794837382, which, uh, will appear as such. ID does not realize it "is" the value of an en dash added to the value of a page break; it's just a number.
What's the difference when you use text strings? Usually, the following construction will work:
story.insertionPoints.lastItem().contents += 'hello happy world!';
.. but not always! It will fail when the contents of that last insertionPoint is .. one of the SpecialCharacters values. And at that point, you get the same as above (only the other way around).
It works when you use a direct assignment "=" because you can assign either a string value or a SpecialCharacter enumeration to a single character.
Thanks a lot. I think I've got it. Until next time, at least.