1

this is my script and I keep getting this error - I have been trying around all day but don't seem to get it to work. here is the thing: I am running 2 if cases here, every time I remove one of them ( to only insert one document ) it works fine. so the code can't be that wrong. I got it to work before with two ifs but somehow i got stuck with the real pdf documents I need to insert. Any idea of what is wrong?? I have already copied part of a script I found here in a post from 2007, but it does not fix the problem.

set mainfolder to choose folder
tell application "Finder" to set folderList to (sort folders of mainfolder as alias list by name)
display dialog "Ordner docs wählen"
set source_folder to choose folder

repeat with i from 1 to count of folderList
   try
       tell application "Finder" to set Master_File to (files of entire contents of (item i of folderList))
   end try


   repeat with i from 1 to count of folderList
     try
        tell application "Finder" to set Master_File to (files of entire contents of (item i of folderList))
     end try


   tell application "Finder" to set file_list to (files of entire contents of source_folder)

   tell application "Adobe Acrobat Pro"
       open Master_File
       set Master_Doc to document 1
       set PageCount to 0
   end tell

   repeat with this_file in file_list

       tell application "Adobe Acrobat Pro"
           if name of this_file is "xxx.pdf" then
              open (this_file as alias)
              insert pages Master_Doc after PageCount from document 2 starting with 1 number of pages 1
              close document 2 without saving
           end if

           if name of this_file is "yyy.pdf" then
              open (this_file as alias)
              set PageCount to 2
              insert pages Master_Doc after PageCount from document 2 starting with 1 number of pages 5

              close document 2 without saving
           end if

        end tell
    end repeat

 tell application "Adobe Acrobat Pro"
 close Master_Doc saving yes
 end tell

 end repeat

Help is highly appreciated! thanks guys

2
  • could you please show me a screen capture of the folder structor
    – mcgrailm
    Sep 29, 2013 at 0:07
  • i have answered attempted to answer your question pleas have the courtesy to reply
    – mcgrailm
    Oct 1, 2013 at 20:26

1 Answer 1

1

I'm not sure if this is exactly what you were trying to do but I think i got it.

in your post you use the same i variable in the nested loop you should always use a new variable whenever your nest a loop or you will run into problems

set mainfolder to choose folder
set source_folder to choose folder
tell application "Finder"
    set folderList to (sort folders of mainfolder as alias list by name)

    repeat with afolder in folderList
        set afolder to afolder as alias
        set Master_File to (first file of folder afolder)
        tell application "Adobe Acrobat Pro"
            open Master_File
            set Master_Doc to document 1
            set PageCount to 0
        end tell

        set file_list to (files of entire contents of source_folder)
        repeat with this_file in file_list

            tell application "Adobe Acrobat Pro"
                if name of this_file is "xxx.pdf" then
                    open (this_file as alias)
                    insert pages Master_Doc after PageCount from document 2 starting with 1 number of pages 1
                    close document 2 without saving
                end if

                if name of this_file is "yyy.pdf" then
                    open (this_file as alias)
                    set PageCount to 2
                    insert pages Master_Doc after PageCount from document 2 starting with 1 number of pages 5

                    close document 2 without saving
                end if

            end tell
        end repeat

    end repeat
    tell application "Adobe Acrobat Pro" to close Master_Doc saving yes
end tell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.