repeat loop problems

Hi all,

I am having problems with this script, mostly the second repeat loop. I need a little help. I am trying to open documents in each “month” folders and print a PostScript file to an “In” folder for Acrobat Distiller to watch and create a PDF file.

I am using OS 9.1, FaceSpan 3.5, QuarkXPress 4, and PreFab Player.

Thanks. Sean


on hilited theObj
	set Counter to 0
	tell application "Finder"
		activate
		set CommonPath to folder "PDF Folder" of folder "Misc Storage" of desktop
		set Monthcounter to 1
		repeat while Monthcounter < 13
			if Monthcounter is equal to 1 then
				set MonthFolder to "January Production"
				if Monthcounter is equal to 2 then
					set MonthFolder to "February Production"
					if Monthcounter is equal to 3 then
						set MonthFolder to "March Production"
						if Monthcounter is equal to 4 then
							set MonthFolder to "April Production"
							if Monthcounter is equal to 5 then
								set MonthFolder to "May Production"
								if Monthcounter is equal to 6 then
									set MonthFolder to "June Production"
									if Monthcounter is equal to 7 then
										set MonthFolder to "July Production"
										if Monthcounter is equal to 8 then
											set MonthFolder to "August Production"
											if Monthcounter is equal to 9 then
												set MonthFolder to "September Production"
												if Monthcounter is equal to 10 then
													set MonthFolder to "October Production"
													if Monthcounter is equal to 11 then
														set MonthFolder to "November Production"
														if Monthcounter is equal to 12 then
															set MonthFolder to "December Production"
														end if
													end if
												end if
											end if
										end if
									end if
								end if
							end if
						end if
					end if
				end if
			end if

			repeat while Monthcounter < 13
				set OrigpathBK to folder "Bank" of folder MonthFolder of CommonPath

				set NewpathBK to folder "In" of folder "Bank" of folder MonthFolder of CommonPath

				tell OrigpathBK
					set filelist to (every file whose (file type is "XDOC"))
					repeat with thisfile in filelist
						if exists thisfile then
							open thisfile
						end if
						tell application "QuarkXPress™ 4.11"
							activate
							tell application "PreFab Player™"
								try
									do menu menu item "Export as PDF..." of menu "Utilities"
									set Counter to Counter + 1
									click button 1
									if exists button 1 then
										click button 1
										if exists button 1 then
											click button 1
										end if
									end if
								on error number errNum -- error trap
									if errNum is -1712 then
										tell application "QuarkXPress™ 4.11"
											close thisfile saving no
										end tell
										tell application "Finder"
											if not (exists folder "ERRORS" of OrigpathBK) then
												make new folder at OrigpathBK
												select folder "untitled folder"
												set name of selection to "ERRORS"
											end if
											move thisfile to folder "ERRORS" of OrigpathBK
										end tell
									else if errNum is -1712 and (exists button 2) then -- error with clicking save
										click button 2
										tell application "QuarkXPress™ 4.11"
											close thisfile saving no
										end tell
										tell application "Finder"
											if not (exists folder "ERRORS" of OrigpathBK) then
												make new folder at OrigpathBK
												select folder "untitled folder"
												set name of selection to "ERRORS"
											end if
											move thisfile to folder "ERRORS" of OrigpathBK
										end tell
									end if
								end try -- end error trap
							end tell
							if exists document 1 then
								close document 1 saving no
							end if
						end tell
					end repeat
				end tell
				move (every file of CommonPath whose (file type is not "XDOC")) to NewpathBK with replacing
				set Monthcounter to Monthcounter + 1
			end repeat
		end repeat
	end tell

end hilited

Hi, Sean.

I’ve unnested your code a bit. I don’t have FaceSpan, QuarkXPress, or PreFab Player, so I’ve no idea if the following actually works, but it should be a little easier to debug now… :slight_smile:

on hilited(theObj)
  set Counter to 0
  set CommonPath to ((path to desktop as string) & "Misc Storage:PDF Folder:") as alias
  set folderNames to {"January Production", "February Production", "March Production", "April Production", "May Production", "June Production", "July Production", "August Production", "September Production", "October Production", "November Production", "December Production"}
  
  repeat with MonthCounter from 1 to 12
    set MonthFolder to item MonthCounter of folderNames
    
    tell application "Finder"
      set OrigpathBK to folder "Bank" of folder MonthFolder of CommonPath
      set NewpathBK to folder "In" of OrigPathBK
      
      set filelist to (every file of OrigpathBK whose file type is "XDOC")
    end tell
    
    repeat with thisfile in filelist
      tell application "Finder" to open thisfile
      
      try
        tell application "QuarkXPress™ 4.11"
          activate
          tell application "PreFab Player™"
            do menu menu item "Export as PDF..." of menu "Utilities"
            set Counter to Counter + 1
            click button 1
            if exists button 1 then
              click button 1
              if exists button 1 then
                click button 1
              end if
            end if
          end tell
        end tell*)
      on error number errNum -- error trap
        if errNum is -1712 then
          tell application "QuarkXPress™ 4.11"
            tell application "PreFab Player™"
              if (exists button 2) then click button 2
            end tell
            close thisfile saving no
          end tell
          
          tell application "Finder"
            if not (exists folder "ERRORS" of OrigpathBK) then
              make new folder at OrigpathBK with properties {name:"ERRORS"}
            end if
            move thisfile to folder "ERRORS" of OrigpathBK
          end tell
        end if
      end try -- end error trap
      
      tell application "QuarkXPress™ 4.11"
        if exists document 1 then close document 1 saving no
      end tell
    end repeat
    
    tell application "Finder"
      move (every file of CommonPath whose file type is not "XDOC") to NewpathBK with replacing
    end tell
  end repeat
  
end hilited

If Monthcounter isn’t equal to 1, then the test for (Monthcount = 2) will never get called. The syntax you need is “else if”:


if ( monthcounter = 1 ) then

    set MonthFolder to "January Production"

else if ( monthcounter = 2 ) then

    set MonthFolder to "Feburary Production"

else if ETC...

else
    -- in the final else block, you place code that should run if none
    -- of the above "else if" statements were true
end if


Thanks!

I got this script to work.

Sean