Copy link to clipboard
Copied
I'm new to scripting and was wondering if it would be possible to creat unique hyperlinks based on a grep?
I have an indesign file with lots of six digit item numbers. Can I grep for \d{6} and create a hyperlink like google.com/123456 with that number as the anchor text? The digits are unique but the base URL is the same throughout (In this example google.com/).
I was trying with AppleScript but if the number repeated then the script failed.
Any help is is much appreciated.
Thank you
I think I solved it with this:
var myDoc = app.activeDocument; | |
app.findGrepPreferences = app.changeGrepPreferences = null; | |
app.findGrepPreferences.findWhat = "\\d{6}-.{2}"; | |
var myFound1 = myDoc.findGrep(); |
count = 0 | |
for(k=0; k<myFound1.length; k++) | |
{ | |
try{ | |
var myFind = myFound1 | |
var myFound = (myFound1 | |
var classNo = myFound.split("-"); | |
var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(myFound1 | |
var myHyperlinkURLDestination = app.activeDocument.hyperlinkURLDestinations |
Copy link to clipboard
Copied
Bonjour roba,
Regarde -> Create hyperlinks with script, without big increases to size and processing reqs of resulting PDFs?
voici :
#target "indesign-12.064" // CC2017
app.findGrepPreferences = app.changeGrepPreferences = null;
var doc = app.activeDocument;
app.findGrepPreferences.findWhat = '\\d{6}';
var objs = doc.findGrep();
for (var i = 0; i < objs.length; i++) {
//
var currTarget = objs;
var lnkDest = doc.hyperlinkURLDestinations.add("http://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html");
var lnkSrc = doc.hyperlinkTextSources.add(currTarget);
var lnk = doc.hyperlinks.add(lnkSrc, lnkDest);
}
alert('Processed '+objs.length+' hyperlinks');
cet exemple est tiré du lien cité plus au il fonction.
Copy link to clipboard
Copied
I think I solved it with this:
var myDoc = app.activeDocument; | |
app.findGrepPreferences = app.changeGrepPreferences = null; | |
app.findGrepPreferences.findWhat = "\\d{6}-.{2}"; | |
var myFound1 = myDoc.findGrep(); |
count = 0 | |
for(k=0; k<myFound1.length; k++) | |
{ | |
try{ | |
var myFind = myFound1 | |
var myFound = (myFound1 | |
var classNo = myFound.split("-"); | |
var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(myFound1 | |
var myHyperlinkURLDestination = app.activeDocument.hyperlinkURLDestinations.add("https://www.apexprd.org/scripts/webtrac.wsc/Wbsearch.html?xxmod=AR&xxactivitynumber="+classNo[0]) | |
var myHyperlink = app.activeDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkURLDestination, {name: myFound1 | |
count++ | |
}catch(e){} | |
} | |
alert(count/2 + " occurencces is changed") |