Copy link to clipboard
Copied
Hello,
I made a people directory document in InDesign using data merge. Each person has information about his/her social network URLs (LinkedIn, Twitter).
Is it possible to make a script which searches the InDesign document for all strings looking like this:
LinkedIn Profile: http://a-very-long-url
and transforms them into just LinkedIn Profile but with the URL applied as a hyperlink?
If it's easier for the find/replace operation I could mark the string with delimiters before running the script, to avoid complex URL detection scripting. Maybe something like this (Markdown style): [LinkedIn Profile](http://a-very-long-url/)
Thank you!
Hi,
Quick snippet, try ...
...var doc = app.activeDocument;
// get URL
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?<=LinkedIn Profile: )(https?|www)\\S+\\>';
var mURL = doc.findGrep();
// get Texte
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = 'LinkedIn Profile:';
var mSource = doc.findGrep();
for (var k = 0; k <mSource.length; k++){
var mHyperlinkD
Copy link to clipboard
Copied
Hi,
Quick snippet, try ...
var doc = app.activeDocument;
// get URL
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?<=LinkedIn Profile: )(https?|www)\\S+\\>';
var mURL = doc.findGrep();
// get Texte
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = 'LinkedIn Profile:';
var mSource = doc.findGrep();
for (var k = 0; k <mSource.length; k++){
var mHyperlinkDestination = doc.hyperlinkURLDestinations.add(mURL
.contents); var mHyperlinkTextSource = doc.hyperlinkTextSources.add(mSource
); mHyperlink = doc.hyperlinks.add(mHyperlinkTextSource,mHyperlinkDestination);
mHyperlink.name =mURL
.contents; mHyperlink.visible=false;
}
//remove URL text
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?<=LinkedIn Profile: )(https?|www)\\S+\\>';
app.changeGrepPreferences.changeTo = '';
doc.changeGrep();
//rename 'LinkedIn Profile: ' to 'LinkedIn Profile'
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = 'LinkedIn Profile: ';
app.changeGrepPreferences.changeTo = 'LinkedIn Profile';
doc.changeGrep();
Copy link to clipboard
Copied
Thank you! Your script worked very well. ![]()
Copy link to clipboard
Copied
Thank you for providing Ronald. This was super useful. However, being unfamiliar with coding I'm having trouble tweaking the code so it will operate for my purposes. Instead of hyperlinking LinkedIn Profile: I need to hyperlink #1111 but the digits can be variables and there may also be five digits at times.
Sample below:
How would I go about doing this?
After the # is where I'm stuck:
var doc = app.activeDocument;
// get URL
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?<=# )(https?|www)\\S+\\>=';
var mURL = doc.findGrep();
// get Texte
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '#';
var mSource = doc.findGrep();
for (var k = 0; k <mSource.length; k++){
var mHyperlinkDestination = doc.hyperlinkURLDestinations.add(mURL
var mHyperlinkTextSource = doc.hyperlinkTextSources.add(mSource
mHyperlink = doc.hyperlinks.add(mHyperlinkTextSource,mHyperlinkDestination);
mHyperlink.name =mURL
mHyperlink.visible=false;
}
//remove URL text
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?<=# )(https?|www)\\S+\\>=';
app.changeGrepPreferences.changeTo = '';
doc.changeGrep();
Copy link to clipboard
Copied
Greetings,
That script worked well.
How can I tweak it to do the same for sets of digits
Sample below:
#10476 https://thiswebsite...
#10536 https://thiswebsite...
#12784 https://thiswebsite...
Here is what I tried:
var doc = app.activeDocument;
// get URL
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?<=\\d{5})(https?|www)\\S+\\>';
var mURL = doc.findGrep();
// get Texte
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '\\d{5}';
var mSource = doc.findGrep();
for (var k = 0; k <mSource.length; k++){
var mHyperlinkDestination = doc.hyperlinkURLDestinations.add(mURL
var mHyperlinkTextSource = doc.hyperlinkTextSources.add(mSource
mHyperlink = doc.hyperlinks.add(mHyperlinkTextSource,mHyperlinkDestination);
mHyperlink.name =mURL
mHyperlink.visible=false;
}
//remove URL text
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?<=\\d{5} )(https?|www)\\S+\\>';
app.changeGrepPreferences.changeTo = '';
doc.changeGrep();
//rename '#\d\d\d\d\d ' to '#\d\d\d\d\d '
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '\\d{5} ';
app.changeGrepPreferences.changeTo = '\\d{5}';
doc.changeGrep();
------------------------------------
What am I doing wrong?
It keeps saying the error is in LINE 12
...Please and thanks
Copy link to clipboard
Copied
The reason might be a missing Space in the first GREP query (line 4)
original:
app.findGrepPreferences.findWhat = '(?i)(?<=\\d{5})(https?|www)\\S+\\>';
how it should be:
app.findGrepPreferences.findWhat = '(?i)(?<=\\d{5} )(https?|www)\\S+\\>';
Greetings
Copy link to clipboard
Copied
Thanks for your help,
It was not the space.
Note: The first script, at the top of the page, with the LINKEDIN: verbiage, worked perfect.
I would need to replace LINKEDIN with the numbers like: '#10429'
Again, thanks for you reply and help.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more