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

Find Web address and apply the character style

Engaged ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

Hi Everyone !

I wrote this script to find the all web address (http|www.|https) and apply the character styles. Below script works fine, but now i remove the (http|www.|https) like, www.google.com to google.com. Could you please find solution for that.

Any help will be greatly appreciated!! Thanks!

if (app.documents.length==0)

{

alert("please open the InDesign Document and then run the tool!");

exit(0);

}

var myDoc = app.activeDocument;

if(app.activeDocument.characterStyles.itemByName("!text udl").isValid == true)

{

var mycode = "(?i)(http|ftp|www)\\S+[\\l\u|\\d\\/]";

app.findGrepPreferences = app.changeGrepPreferences = null; 

      

app.findGrepPreferences.findWhat = mycode;  

var found_B = app.activeDocument.findGrep();

for(var i =0;i<found_B.length;i++)

 

{

found_B.appliedCharacterStyle = app.activeDocument.characterStyles.itemByName("!text udl");

}

}

else

{

alert("Please Ensure the character styles name '!text udl' in Character style Pallate")

exit(0);

}

app.findGrepPreferences = app.changeGrepPreferences = null; 

alert("Process Completed")

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
TOPICS
Scripting

Views

1.2K

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

Community Expert , Aug 17, 2019 Aug 17, 2019

You keep on changing your question, creating quite a bit of confusion. In the original code that i gave if your character style applied underline there is no need for code change, i am not sure what was not working for you if you yourself say that the code works fine. However look at the code below, i have changed the grep a bit and it works fine for your problem of underline as well, even though the original code i gave also works fine for me with the underlining for your example

Make sure you h

...

Votes

Translate

Translate
Community Expert ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

HI,

If you are looking for all (Hyper)links then you could use the hyperlinks object of the document.

var links = app.activeDocument.Hyperlinks;

and then just loop through each one.

Hope this helps

Malcolm

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
Community Expert ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

Try the following code

if (app.documents.length==0)

{

    alert("please open the InDesign Document and then run the tool!");

    exit(0);

}

var myDoc = app.activeDocument;

if(app.activeDocument.characterStyles.itemByName("!text udl").isValid == true)

{

    var mycode = "(?i)(http|ftp|www)\.(\\S+[\\l\u|\\d\\/])";    

    app.findGrepPreferences = app.changeGrepPreferences = null;          

    app.findGrepPreferences.findWhat = mycode;    

    app.changeGrepPreferences.appliedCharacterStyle = "!text udl"

    app.changeGrepPreferences.changeTo = "$2"

    app.activeDocument.changeGrep()

}

else

{  

    alert("Please Ensure the character styles name '!text udl' in Character style Pallate")

    exit(0);

}

app.findGrepPreferences = app.changeGrepPreferences = null;

alert("Process Completed")

-Manan

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
Engaged ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

Hi Manan, Malcolm and Grefel,

Thanks for the reply...

Manan,

I have used your script and attached before and after screenshots. Help me in finding the web address which excludes "www."

Screen Shot 2019-08-16 at 10.35.25 AM.png        Screen Shot 2019-08-16 at 10.35.32 AM.png

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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
Community Expert ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

Works fine for me, see the attached gif of the code run and result

Demo.gif

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
Engaged ,
Aug 17, 2019 Aug 17, 2019

Copy link to clipboard

Copied

Hi Manan,

Sorry for the confusion..

My actual request is need to apply the underline in all website address. I have used your script and its works fine. At the same time I would removed “www” and “http”, it is look like google.com. Totally I need to apply underline all web address with “http” & “www” and without “http” & “www”. Please help me how can do that?

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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
Engaged ,
Aug 17, 2019 Aug 17, 2019

Copy link to clipboard

Copied

Hi,

I found the Grep code to below link.

Tips & Techniques: Use GREP to find URL's

Grep Code: '\S*?(\.org|\.com|\.net|\.edu|\.us|\.gov|\.biz)+\S*\>/?'

Its working fine. But we have problem with "(www.google.com)". What I have highlighted red, it is taking "(" also underline. Please help me how can do that?

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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
Community Expert ,
Aug 17, 2019 Aug 17, 2019

Copy link to clipboard

Copied

You keep on changing your question, creating quite a bit of confusion. In the original code that i gave if your character style applied underline there is no need for code change, i am not sure what was not working for you if you yourself say that the code works fine. However look at the code below, i have changed the grep a bit and it works fine for your problem of underline as well, even though the original code i gave also works fine for me with the underlining for your example

Make sure you have underline configured in your character style

if (app.documents.length==0)

{

    alert("please open the InDesign Document and then run the tool!");

    exit(0);

}

var myDoc = app.activeDocument;

app.findGrepPreferences = app.changeGrepPreferences = null;

if(app.activeDocument.characterStyles.itemByName("!text udl").isValid == true)

{

    var mycode = "(?i)(http:\/\/|https:\/\/|ftp:\/\/|www\.)(\\S+)(\.gov|\.us|\.net|\.com|\.edu|\.org|\.biz)";    

    app.findGrepPreferences = app.changeGrepPreferences = null;          

    app.findGrepPreferences.findWhat = mycode;    

    app.changeGrepPreferences.appliedCharacterStyle = "!text udl"

    app.changeGrepPreferences.changeTo = "$2$3"

    app.activeDocument.changeGrep()

}

else

{  

    alert("Please Ensure the character styles name '!text udl' in Character style Pallate")

    exit(0);

}

app.findGrepPreferences = app.changeGrepPreferences = null;

alert("Process Completed")

-Manan

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
Engaged ,
Aug 18, 2019 Aug 18, 2019

Copy link to clipboard

Copied

LATEST

Hi Manan,

Words cannot express how grateful I am for your help. You were there for me when I needed it the most. Thank you for everything that you've done to help me.

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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
Community Expert ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

If you want to create Hyperlinks from URLs. This is a quite difficult task... You could have a look at this script

GitHub - grefel/createHyperlinks: Create InDesign hyperlinks from URLs and mail adresses

which performs far better than the shipped version at the hyperlinks panel. But you will still find edge cases where a valid URL is not located.

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