4 Replies Latest reply on Oct 11, 2011 3:55 PM by myDwayneSmith

    [AS][CS4] problem with display dialog in repeat loop

    myDwayneSmith Level 1

      Hi all

       

      I'm trying to troubleshoot a section of a large script using a 'display dialog' command.

      (dsCopy is the result of a dialog, dsFile is a string, theCalendarList is a list of strings)

       

      Everything seems to work fine, except the dialog is never displayed and the next 'if' is processed instead.

      tell application "Adobe InDesign CS4"

          --------

          --------

          if dsCopy is 0 then

              set CopyFromFlyerList to {my dsWC_CopyFromFlyer(), my dsSS_CopyFromFlyer(), my dsCC_CopyFromFlyer()}

              set thisItem to 0

              repeat until (item thisItem of theCalendarList) = dsFile

                  set thisItem to thisItem + 1

                  display dialog "are we there yet?"

                  if dsFile = item thisItem of theCalendarList then

                      item thisItem of CopyFromFlyerList

                  end if

              end repeat

          else

              --------

              --------

          end if

      end tell

      I've got no idea what I'm doing wrong here.

       

      Thanks for any help

      d.

        • 1. Re: [AS][CS4] problem with display dialog in repeat loop
          SuperMacGuy Level 2

          Are you saying that the block

          if dsFile = item thisItem of theCalendarList then

                 item thisItem of CopyFromFlyerList

          end if

          occurs before any display dialog, or that block is totally skipped and you jump out of the block "if dsCopy is 0 then ..." and onto some other function after that?

           

          Can you just add some log statements, or "tell me to log ..." and have those report something?

          • 2. Re: [AS][CS4] problem with display dialog in repeat loop
            myDwayneSmith Level 1

            Thanks SuperMacGuy

            Yes, that's exactly what I'm saying — the "if dsFile..." statement pulls and runs the subroutine from CopyFromFlyerList without a dialog ever appearing.

             

            Of course, I've asked entirely the wrong question. I'm using the display dialog command to work out what the REAL problem is. What I'm really trying to work out is why the repeat loop continues even after "dsFile = item thisItem of theCalendarList".

            This portion of the script should only run one subroutine from CopyFromFlyerList and then move on — but after the first subroutine runs, this loop (I think) tries to pull and run another one.

             

            I'll try your log suggestion when I get back to work on Monday.

            d.

            • 3. Re: [AS][CS4] problem with display dialog in repeat loop
              SuperMacGuy Level 2

              I'm re-reading your code and I think this is strange:

               

              set thisItem to 0

                      repeat until (item thisItem of theCalendarList) = dsFile

               

              would expand to:

              set thisItem to 0

                      repeat until (item 0 of theCalendarList) = dsFile

               

              and so this would never repeat? I'm not sure it would run once, getting item 0 won't work in AS. Objective-C arrays work with index starting at 0, but not Applescript. Do you need to start with item 1?

              1 person found this helpful
              • 4. Re: [AS][CS4] problem with display dialog in repeat loop
                myDwayneSmith Level 1

                Yeah, thanks SuperMacGuy.

                 

                The whole section of code is strange and ridiculous. The problem is actually this:

                set CopyFromFlyerList to {my dsWC_CopyFromFlyer(), my dsSS_CopyFromFlyer(), my dsCC_CopyFromFlyer()}

                I was trying to put a bunch of subroutine calls into a list and have the script pluck out the correct one. But, and it seems obvious to duncy me now, it's just running those subroutines instead of putting them into a list. So, the script is never actually getting to the repeat loop. It was just coincidence that I was testing it with files that required the first subroutine (that's why it appeared to be working correctly initially).

                 

                I've just been trying to simplify the code of a script that works, but I haven't hit gold with this section, so I'm going to revert back to what was working previously.

                 

                Thanks for your time SuperMacGuy

                Much appreciated

                d.