Skip to main content
Fred.L
Inspiring
August 3, 2022
Answered

Script UI - hyperlink with Static text

  • August 3, 2022
  • 3 replies
  • 1564 views

Hi guys,

I've started to script and struggle finding how I can make a static text act as an hyperlink?

Here is the code I've done, and the interface I've done so far.

I'd like to be able to clic and access to proper website from the two static texts at the bottom of the window. How can I achieve that ?

 

Thanks for the help

var myEan14Site = w.add ("group");
var myEan14web = w.add ("group");
myEan14Site.add ("statictext", undefined, "https://www.free-barcode-generator.net/ean-14/");

 

This topic has been closed for replies.
Correct answer Marc Autret

Hi @Fred.L 

 

 

Best,

Marc

 

 

3 replies

Kasyan Servetsky
Legend
August 4, 2022

Marc outstripped me while I was preparing my sample script.
Here's how I do this:

var scriptName = "My Test";
CreateDialog();

function CreateDialog() {
	var tmpFileName = scriptName.replace(/\-\s\d+\.\d+$/, "").replace(/\s+/g, "_").toLowerCase();
	var w = new Window("dialog", scriptName);
	
	w.p = w.add("panel", undefined, "Panel:");
	w.p.orientation = "column";
	w.p.alignment = "fill";
	w.p.alignChildren = "left";
	
	w.p.g = w.p.add("group");
	w.p.g.orientation = "row";
	w.p.g.st = w.p.g.add("statictext", undefined, "Click me");
	w.p.g.st.graphics.foregroundColor =w.p.g.st.graphics.newPen(w.p.g.st.graphics.PenType.SOLID_COLOR, [0, 0, 1], 1);
/*
	var wgx = w.graphics,
	linePen = wgx.newPen(wgx.PenType.SOLID_COLOR,[0,0,1], 1);

	w.p.g.st.preferredSize[1] += 3;

	w.p.g.st.onDraw = function() {
		var gx = this.graphics,
		sz = this.preferredSize,
		y = sz[1]-1;

		gx.drawOSControl();
		gx.newPath();
		gx.moveTo(0, y);
		gx.lineTo(sz[0],y);
		gx.strokePath(linePen);
	};
*/
	w.p.g.st.addEventListener("click", JumpToLink);

	// Buttons
	w.bts = w.add("group");
	w.bts.orientation = "row";   
	w.bts.alignment = "center";
	w.bts.ok = w.bts.add("button", undefined, "OK", {name:"ok"});
	w.bts.cancel = w.bts.add("button", undefined, "Cancel", {name:"cancel"});
	
	var showDialog = w.show();
	
	if (showDialog == 1) {
		Main();
	}	
}

function JumpToLink() {
	var tmpFolder = new Folder(Folder.temp.absoluteURI + "/InDesignScripts");
	tmpFolder.create();
	tmpFolder.create();
	var linkJumper = File(tmpFolder.absoluteURI + "/" + tmpFileName + "_temp.html");

	if (!linkJumper.exists) {
		linkJumper.open("w");
		var linkBody = '<html><head><META HTTP-EQUIV=Refresh CONTENT="0; URL=https://www.free-barcode-generator.net/ean-14/"></head><body> <p></body></html>'
		linkJumper.write(linkBody);
		linkJumper.close();
	}

	linkJumper.execute();
}

function Main() {
	alert("Finished.", scriptName);
}

When you click the 'quasi-link' (static text), the JumpToLink function creates a simple web page with the target URL in the temp folder and executes it.

 

In older InDesign versions (and currently in ESTK), we could go even further and add an underline so it looks like a real hyperlink:

But in recent versions, something went broken in Script UI and it doesn't work anymore: the static text gets hidden.

I included but out-commented the part of the code that makes the underline. By the way, it was created by Marc.

 

 

 

 

 

 

 

Fred.L
Fred.LAuthor
Inspiring
August 4, 2022

Thanks Kasyan !

 
After declaring var tmpFileName with the proper url, it worked as a charm !
This step is done !
 
I'm progressing ^^
Thanks a lot
Marc Autret
Marc AutretCorrect answer
Legend
August 4, 2022

Hi @Fred.L 

 

 

Best,

Marc

 

 

Fred.L
Fred.LAuthor
Inspiring
August 4, 2022

Thanks @Marc Autret 

I understand it was not as simple as put a tag 'link:' …

Thanks for the link, I have something on my plate to think about now.

brian_p_dts
Community Expert
Community Expert
August 4, 2022

You'd have to write a plugin or use VBScript or Applescript probably to achieve that. Extendscript doesn't really call outside programs like a web browser on its own. You could turn the static text into a button the onclick use app.doScript that passes the text as an argument. But not exactly trivial. Maybe someone else has a better idea.