4 Replies Latest reply on Feb 12, 2015 12:36 AM by Stamm

    phone number hyperlink

    rudytj

      I have a directory of doctors names and addresses that is being repurposed from print to an online presence. I would like the phone numbers to be hyperlinks when viewed on a smartphone so clicking them will dial the number clicked.

       

      I know this can be done by making the hyperlink be "tel:+000-000-0000" so i can do it manually... but there are hundreds of phone numbers in this directory.

       

      They already are on a line of there own and assigned a unique paragraph style.

       

      Dr John Doe

      123 Main Street

      Anytown, PA 12345

      123-123-1234

       

      So is it possible to find that paragraph style, copy the paragraph, open the hyperlink panel, create a new hyperlink, add tel:+  and then add in the copied phone number. And then proceed to the next instance.

        • 1. Re: phone number hyperlink
          rudytj Level 1

          just a morning bump....

          • 2. Re: phone number hyperlink
            Stamm Level 1

            Hey, this should do your trick:

             

            myDoc = app.documents[0];

            function tagHyperlinks(object){

                        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

                        app.findGrepPreferences.findWhat = ".+";

                        app.findGrepPreferences.fontStyle = "Bold Italic";

                        for(i = 0; i < object.length; i++){

                            theText = object[i].findGrep();

                            for(ta = 0; ta < theText.length; ta++){

                                try{

                                     myHyperlinkURL = myDoc.hyperlinkURLDestinations.add('tel:' + theText[ta].contents);

                                     myHyperlinkSource = myDoc.hyperlinkTextSources.add(theText[ta]);

                                     myHyperlink = myDoc.hyperlinks.add(myHyperlinkSource, myHyperlinkURL);

                                     myHyperlink.visible = false;

                                 }

                                catch(myError){}

                            }

                        }

            }

            tagHyperlinks(app.documents[0].textFrames);

             

            Please note, that this only works for your example. You may need to change the "findGrep" style, to what is unique to your tel. number. eg.: "oblique" or "italic", etc.

            Hope this helps

            1 person found this helpful
            • 3. Re: phone number hyperlink
              rudytj Level 1

              thanks but i am missing something....i cannot get it to find any text. I keep getting an error that states:

               

              error number 33794

              error string: object contains no text for find/change.

               

              I have changed the line "findgrep" style to be "medium" because the text is set in whitney medium in the document.

              I have also experimented with changing the script to be looking for a paragraph style called "phone" that didn't work either.

              ... i am over my head with this.

               

              I would greatly appreciate if you can help me again. and if i could be so bold ask that you break out what the different lines are doing. in particular what do the .+ and the i++ etcetera mean?

               

              if i am to ignorant and being a bother i do understand but i am trying to learn. its just frustrating knowing that it can be done but not being able to figure it out

               

              scott

              • 4. Re: phone number hyperlink
                Stamm Level 1

                Hey,

                 

                this error appears when a wrong object is being searched. So our "app.documents[0].textFrames" doesn't work. You need to change this line and the "myDoc = app.documents[0]" to the document which should be changed. If you want to use exactly this code, make sure Indesign is open and only your desired document is open. Then there shouldn't be such an error.

                 

                In "findWhat" you can use javascript's regular Expression. You can find many tutorials about this on the internet. '.+' basically indicates that all types of text is selected. In our case we can just use the findStyle, as you have a different style on all of your numbers. We could also change the "findWhat" to "[0-9-]*". This would select only numbers and dashes.

                 

                The i++ is another way of writing i = i+1. If you don't know about "for" loops, there is also a lot of information on the internet. Just search for "for loop javascript". The i++ as third parameter in the for loop indicates that i is being incremented by 1 after each iteration. One iteration is from the opening curly brackets to the closed ones. 

                 

                theText saves all strings which match our findWhat and findGrep parameters. In the second for loop we just add a new hyperlink + assign the hyperlink to our text.

                 

                Hope this helps