6 Replies Latest reply on Apr 18, 2009 12:12 AM by low Jackson

    Check Dates in a document

    low Jackson Level 1

      Hello, I need to check all the dates (day/date/month) in a document to a list of predetermined fixtures (around 200 dates) to make sure they are correct.

       

       

      My plan is to search the document using the following grep find...

       


      (Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\s(1|2|3|4|5|6|7|8|9|10|11|12|13 |14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\s(January|February|March|April|May |June|July|August|September|October|November|December)

      ...then check the text found against my list of fixture, if its not found it will show an alert.
      Can anyone tell me if there is a better way and where they would start scripting in Applescript?
      many thanks
      LJ
        • 1. Re: Check Dates in a document
          [Jongware] Most Valuable Participant

          You'll be happy to learn that your GREP should work just fine; with the provision that that is the exact way all dates are written: day-of-week, day, month.

          Using findGrep does not exactly work the same as in the interface, rather, it returns an array of found items. That's right, you get the entire list of all dates at once.

           

          I'm not at all familiar with AppleScript (ask again if you are content with JS), but I think it is totally feasible to do this:

           

          • create an array of all 'good' dates. If you have a list, convert that to something you can insert right into your script. Be sure to use the exact same format you will be searching.
          • do the GREP find. It returns an array; check its length, it should be larger than 0 if it found anything.
          • compare each found item against your list. If it's in there, you're okay. If not, you could issue an alert (thereby stopping the script!), or -- a trick that works nicely for me -- just assign a "Bad" colour to the offending text. If you want to use this method, first create a swatch of, say, a bright red, and name it "Bad!". Then assign that swatch to 'bad' dates.
          • When the script is done, search for "Bad!" coloured text. Check then manually, delete, or correct, or do whatever you are supposed to do.
          • Finally, delete the "Bad!" swatch and replace it with Black. (Assuming your plain text is also black, of course.)
          1 person found this helpful
          • 2. Re: Check Dates in a document
            low Jackson Level 1

            Hi [Jongware]

             

            Yeah, thats about it, I'm not to worried about the flagging with the Red as each document will only have a few dates on it.

             

            thanks for the offer of a JS - if you have time then great, but I'm more into AS so I can keep learning.

             

            LJ

            • 3. Re: Check Dates in a document
              Eric @ MCA Level 3

              Wouldn't it be easier to search on...

               

              (Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\s[1-3]?\d\s(January|February|Ma rch|April|May|June|July|August|September|October|November|December)

               

              instead of enumerating all 31 days? Same effect, I think, although admittedly it will find thround 39 instead of 31...

               

              Script-wise, Jong's plan is good. Arrays are called lists in AS. So the bare bones of it would be something like this, I think:

              tell application "Adobe InDesign CS3"
                tell active document
                  display dialog "Find bad dates or clear bad dates color?" buttons {"Clear", "Find"} default button 2
                  if button returned of result = "Find" then
                    set badCount to 0
                    set myGrepString to "(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\\s[1-3]?\\d\\s(January|February|March|April|May|June|July|August|September|October|November|December)"
                    set goodDateList to {"Monday 13 December", "Tuesday 15 February", "Monday 1 June"} --Fill with real ones
                    try
                      set mySwatch to make color with properties {name:"BAD DATES", model:spot, space:CMYK, color value:{0.0, 100.0, 0.0, 0.0}}
                    end try
                    tell application "Adobe InDesign CS3"
                      set find grep preferences to nothing
                      set change grep preferences to nothing
                      set find what of find grep preferences to myGrepString
                    end tell
                    set foundList to find grep
                    
                    repeat with thisDate in foundList
                      if goodDateList does not contain (thisDate as string) then
                        set fill color of every character of thisDate to color "BAD DATES"
                        set badCount to badCount + 1
                      end if
                    end repeat
                    display dialog "Found "&badCount&" bad dates." buttons "OK" default button 1
                  else
                    try
                      delete color "BAD DATES" replacing with color "Black"
                    on error
                      display dialog "Can't find BAD DATES color to delete."
                    end try
                  end if
                end tell
              end tell
              
              

              EDIT: Be careful copying this script! Whenever I copy it out of the browser, December gets a space in it and becomes Decembe r...

              • 4. Re: Check Dates in a document
                [Jongware] Most Valuable Participant

                Eric, if I could write AS that's what I would'ave written

                 

                Shall we share the points?

                1 person found this helpful
                • 5. Re: Check Dates in a document
                  Eric @ MCA Level 3

                  LOL, fine by me!

                  • 6. Re: Check Dates in a document
                    low Jackson Level 1

                    Thanks so much for this! I can start adding to this.

                     

                     

                    LJ