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

Use script and Grep to creat unique hyperlinks

New Here ,
Feb 13, 2017 Feb 13, 2017

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

TOPICS
Scripting
995
Translate
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

New Here , Feb 14, 2017 Feb 14, 2017

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.contents);
var classNo = myFound.split("-");
var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(myFound1)
var myHyperlinkURLDestination = app.activeDocument.hyperlinkURLDestinations
...
Translate
Enthusiast ,
Feb 14, 2017 Feb 14, 2017

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.

Translate
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 ,
Feb 14, 2017 Feb 14, 2017
LATEST

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.contents);
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.contents+count++})
count++
}catch(e){}
}
alert(count/2 + " occurencces is changed")
Translate
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