I'm trying to create an InDesign script that functions exactly like SplitStory.jsx, only that it won't require first selecting a threaded text frame but instead loops through everything that is threaded/linked within the whole document.
Here is what I have so far, but it doesn't seem to be doing anything. I'm pretty new to scripting.
main();
function main(){
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if(app.documents.length != 0){
var myDoc = app.activeDocument;
var myStories = 0;
for (var i = 0; myDoc.stories.length > i; i++)
myStories = myDoc.stories[i];
mySplitStory(myStories);
myRemoveFrames(myStories);
}
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();
}
}
I feel like I need to add something to mySplitStory(myStories);
like mySplitStory(myStories.currentStory);
, but I can't find anything about this specifically online (or in Adobe's scripting documentation - but maybe I'm not looking in the right places).
Any help would be greatly appreciated!