9 Replies Latest reply on Jul 28, 2010 2:49 AM by Marijan Tompa [tomaxxi]

    alert ( phone number)

    Mickeske

      hi

       

       

       

       

       

      To find a telephone number in a text, I use the following:

       

      app.findGrepPreferences.findWhat = '"32\d\d\d\d\d\d\d\d\d\d";

      var number= myDoc.findGrep(true);

      alert(number);

       

      but if I want to preview this with the alert function, there's no result (is defined as an object instead of text).

       

      help

        • 1. Re: alert ( phone number)
          [Jongware] Most Valuable Participant

          Array of Text findGrep ([reverseOrder: bool]) - Finds text that matches the find what value.

           

          So, alert (number[0]) will show you the first hit (if any), alert (number[1]) the second hit (if any), and so on.

          To see the entire list of found items (again, if any), you can use this:

           

          alert (number.join("\r"));

           

           

          The "if any"'s are because the length of the found items array can also be 0, i.e., when nothing is found.

          • 2. Re: alert ( phone number)
            Peter Kahrel Adobe Community Professional & MVP

            Well, "number" is an array of text objects. To display the first number you'd need

             

            alert (number[0].contents);

             

            To display them all, you need to create an array of text strings:

             

            if (number.length > 0)

               {

               array = [];

               for (i = 0; i < number.length; i++)

                  array.push (number[i].contents);

               alert (number.join ("\r"));

               }

            else

               alert ("No numbers found.");

             

             

            Peter

            1 person found this helpful
            • 3. Re: alert ( phone number)
              Mickeske Level 1

              hi Peter,

               

               

              when i use your script, i got an "[object insertionpoint]" alert. i would like to have a number....

               

              tnx

              • 4. Re: alert ( phone number)
                [Jongware] Most Valuable Participant

                Oops -- Peter is right, you cannot simply use "join" on the return result of findText. (It returns an array of Text, which is a more complicated object, as it also contains all and any formatting, and possibly tables, notes, anchored objects, inline graphics, and more.)

                 

                Peter's script ought to display the results with

                 

                  alert (array.join ("\r"));

                 

                as he stores the contents (which is 'plain' Unicode text) of the "number" array (which is a Text array) into a new array, imaginatively called "array". Must have been a typo.

                • 5. Re: alert ( phone number)
                  Peter Kahrel Adobe Community Professional & MVP

                  Grrr -- of course

                  alert (array.join  ("\r"));

                  thanks, Theun.

                  • 6. Re: alert ( phone number)
                    Peter Kahrel Adobe Community Professional & MVP

                    Which reminds me: alert doesn't scroll, so if you have lots of numbers they roll off the screen and you won't be able to see them. Here is an example from "ScriptUI for Dummies", which is a more useful version of alert: it shows text in a scrollable window. An additional advantage is that you can copy text out of the alert.

                     

                    So the whole script would be this:

                     

                    if (number.length > 0)
                       {
                       array = [];
                       for (i = 0; i < number.length; i++)
                          array.push (number[i].contents);
                       alert_scroll ("Phone numbers", array);
                       }
                    else
                       alert ("No numbers found.");


                    function alert_scroll (title, input)   // string, string
                        {
                        if (input instanceof Array)
                            input = input.join ("\r");
                        var w = new Window ("dialog", title);
                        var list = w.add ("edittext", undefined, input, {multiline: true, scrolling: true});
                        //the list should not be bigger than the maximum possible height of the window
                        list.maximumSize.height = w.maximumSize.height - 100;
                        list.minimumSize.width = 150;
                        w.add ("button", undefined, "Close", {name: "ok"});
                        w.show ();
                        }

                     

                    Peter

                    • 7. Re: alert ( phone number)
                      Loic.Aigon Adobe Community Professional

                      Hi Peter,

                       

                      I discovered your snippet thanks to Tomaxxi and his blog.

                       

                      So I tried and came to wondering if it wasn't missing something ? As I pass long arrays, the list extends and so the window do the same.

                      Finally, the scroll bar never turns active as the items are always fully displayed.

                       

                      Don't we have to set an arbitrary window size to constraign the list in a defined environment ?

                      w.maximumSize.height = 200;

                       

                      Or maybe I misuse something.

                       

                      Thanks anyway for that great code that can be very useful to me :-)

                       

                      Loic

                      • 8. Re: alert ( phone number)
                        Marijan Tompa [tomaxxi] Level 4

                        Hey Loic!

                         

                        Script extends window to the max height and if content is longer than it can fit on screen, then srcoll enables.

                         

                        tomaxxi

                        • 9. Re: alert ( phone number)
                          Loic.Aigon Adobe Community Professional

                          Hi,

                           

                          Definitively needing to sleep and all apologizes, I should have guessed such a problem would have been pointed out a long time ago.

                           

                          Thx Tomaxxi and thanks again to Peter !

                           

                          Loic