// InDesign ExtendScript (JSX) //Written with ChatGPT // If selected text frame has overflow text, get the first word of the next frame in the thread , using that word format the correct string, and insert it in small text fram below the slected text frame // Usage: select a text frame (or text inside it) and run. (function () { if (app.documents.length === 0) { alert("Open a document."); return; } if (app.selection.length !== 1) { alert("Select one text frame (or text inside it)."); return; } var sel = app.selection[0]; var frame1; // Resolve selection to a TextFrame if (sel instanceof TextFrame) { frame1 = sel; } else if (sel.parentTextFrames && sel.parentTextFrames.length > 0) { frame1 = sel.parentTextFrames[0]; } else { alert("Selection is not in a text frame."); return; } // Get the next frame in the thread var frame2 = frame1.nextTextFrame; if (!frame2 || !frame2.isValid) { alert("Selected frame is not linked to a next frame."); return; } if (frame2.words.length === 0) { alert("The next frame has no text."); return; } frame2.parentPage.name //alert("The overflow continues on page: " + frame2.parentPage.name) var firstWord = frame2.words[0].contents; //let's see oif it was successfull in getting the word alert (firstWord) var firstWord = "[ההמשך נמצא בעמ\'" + " " + frame2.parentPage.name + " " + "ד\"ה" + " " + firstWord + "]" //---"[ההמשך נמצא בעמ\' 222 ד\"ה" + " " + firstWord + "]" // Place a new frame right under frame1 (same width) var gb = frame1.geometricBounds; // [y1, x1, y2, x2] var gap = 6; // space below frame1, in pts var top = gb[2] + gap; var left = gb[1]; var right = gb[3]; var initialHeight = 20; var bottom = top + initialHeight; // Add to the same parent container and layer var parentContainer = frame1.parent; var newFrame = parentContainer.textFrames.add(); newFrame.geometricBounds = [top, left, bottom, right]; newFrame.contents = firstWord; newFrame.itemLayer = frame1.itemLayer; // Apply object style "MilatHemshech2" if it exists try { var objStyle = app.activeDocument.objectStyles.itemByName("MilatHemshech2"); if (objStyle.isValid) { newFrame.appliedObjectStyle = objStyle; } else { alert('Object Style "MilatHemshech2" not found. Frame created without style.'); } } catch (e) { alert("Error while applying object style: " + e); } // Allow the frame to auto-size vertically to fit the word try { newFrame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_LEFT_POINT; newFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY; } catch (e) { // ignore if not supported } })();