• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
6

Script sometimes working sometimes not working

Community Beginner ,
Oct 03, 2023 Oct 03, 2023

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();
}
TOPICS
How to , Scripting

Views

239

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2023 Oct 04, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2023 Oct 04, 2023

Copy link to clipboard

Copied

@BarlaeDC  Thanks for getting me back!

 

So I followed your suggestion and I got this message:

Screenshot 2023-10-04 at 22.20.26.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2023 Oct 05, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2023 Oct 05, 2023

Copy link to clipboard

Copied

Why not continue - or at least give a reference - to the original thread?? 

 

https://community.adobe.com/t5/indesign-discussions/script-to-automatically-assign-existing-text-hyp...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2023 Oct 05, 2023

Copy link to clipboard

Copied

LATEST

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... 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines