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

Script UI - hyperlink with Static text

Contributor ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

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/");

 

TOPICS
Scripting

Views

891

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

correct answers 1 Correct answer

Guide , Aug 03, 2022 Aug 03, 2022

Hi @-Dain- 

 

 

Best,

Marc

 

 

Votes

Translate

Translate
Community Expert ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

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. 

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
Guide ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Hi @-Dain- 

 

 

Best,

Marc

 

 

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
Contributor ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

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.

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
Guru ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

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);
}

KasyanServetsky_0-1659599395893.png

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.

KasyanServetsky_1-1659599534081.png

 

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

KasyanServetsky_2-1659599680152.png

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

KasyanServetsky_3-1659599899499.png

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

 

 

 

 

 

 

 

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
Contributor ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

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

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
Contributor ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Hey,

As it happens, opening a web page worked fine the first time but

somehow, even if I change the url, the script keeps opening the first url without taking into account the new one.

I believe we have to implement a way to delete the temporary html file for being able to re-create a new one which will take into account the new url, right ?

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
Contributor ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

never mind, it's actually because of the use of "ScriptName" variable…

I should be able to work something out ^^

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
Guru ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

LATEST

You can add the version number to the scriptName variable so every time you update the script a new html file will be created and opened.

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