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/");
Hi @-Dain-
Best,
Marc
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.
Copy link to clipboard
Copied
Hi @-Dain-
Best,
Marc
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.
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);
}
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.
Copy link to clipboard
Copied
Thanks Kasyan !
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 ?
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 ^^
Copy link to clipboard
Copied
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.