Copy link to clipboard
Copied
So I got this script from the community post and tried this script in InDesign 2023, the script was running and working for few times, but after giving it another try, the script was not running and working anymore, there's no error message popup, so just wondering how to fix this script?
var scriptName = "Change automatically frame with hyperlink text into hyperlinked frame",
debug = false, // for debugging only
doc;
app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, ((File.fs == "Macintosh") ? UndoModes.ENTIRE_SCRIPT : UndoModes.FAST_ENTIRE_SCRIPT), "\"" + scriptName + "\" Script");
//===================================== FUNCTIONS ======================================
function Main() {
try {
var hyperlink, sourceText, textFrame, storedName, newSource, newHyperlink,
doc = app.activeDocument,
hyperlinks = doc.hyperlinks.everyItem().getElements();
for (var i = 0; i < hyperlinks.length; i++) {
hyperlink =hyperlinks[i];
if (!hyperlink.source.hasOwnProperty("sourceText") ||
hyperlink.source.sourceText == undefined
) {
continue;
}
sourceText = hyperlink.source.sourceText;
textFrame = sourceText.parentTextFrames[0];
if (textFrame.extractLabel(scriptName) == "processed") continue;
storedName = hyperlink.name;
try {
newSource = doc.hyperlinkPageItemSources.add(textFrame);
}
catch(err) {
if (debug) $.writeln(err.message + ", line: " + err.line);
continue;
}
newHyperlink = doc.hyperlinks.add(newSource, hyperlink.destination);
hyperlink.remove();
textFrame.insertLabel(scriptName, "processed");
// clear the "Hyperlink" character style
if (sourceText.appliedCharacterStyle.name == "Hyperlink") {
sourceText.appliedCharacterStyle = doc.characterStyles.item("[None]");
sourceText.clearOverrides();
}
newHyperlink.name = storedName;
}
}
catch(err) {
alert("Something went wrong: " + err.message + ", line: " + err.line, scriptName, true);
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function PreCheck() {
if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
doc = app.documents[0];
if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);
if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
Main();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ErrorExit(error, icon) {
alert(error, scriptName, icon);
exit();
}
Copy link to clipboard
Copied
Hi,
Can you re-run the script but change the
debug = false, // for debugging only
line to
debug = true // for debugging only
And see if that gives any more error messages that could help us diagnose the problem.
(as a side note you could also remove )
if (!hyperlink.source.hasOwnProperty("sourceText") ||
hyperlink.source.sourceText == undefined
) {
continue;
}
if (textFrame.extractLabel(scriptName) == "processed") continue;
lines as they add absolutely nothing to the script as far as I can see.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi,
Well that was not the error I was expecting, can you supply a sample document so that I can replicate the problem,
I will keep investigating.
I will continue to try here, but I have not been able to create a document in the correct manner to get this issue.
Copy link to clipboard
Copied
Why not continue - or at least give a reference - to the original thread??
Copy link to clipboard
Copied
This script is marking already processed TextFrames - as "processed" - and ignores them next time - so maybe this is your "problem"?
I'm not sure which line is 16th ... But I'm pretty sure author, @Kasyan Servetsky would be best person to ask for help...