1 2 Previous Next 26 Replies Latest reply: Jun 25, 2012 10:57 AM by Jacques Rioux
big_murph Level 1 Level 1 (0 points)

Hi all,

 

I am just starting out with applescript and could do with a pointer please. I have written a script which saves two pdf files from an active Illustrator document in the source folder of that document. The issue I am have now is that I cannot get the two files to combine into a single PDF file.

 

The whole script is quite long and is works apart from the combine PDF part, I will paste the part of the code I am having problems with and hopefully someone can help me out please:

 

------------------- start of PDF combine script

 

tell application "Finder"

   

    try

        open (every document file of container of file_path whose name contains ".pdf")

    on error

        display dialog "no PDF file located"

    end try

end tell

tell application "Adobe Acrobat Pro" to activate

tell application "Adobe Acrobat Pro"

    set docRefA to the active doc

   

    tell application "Finder"

       

        try

            open (every document file of container of container of file_path whose name contains ".pdf")

        on error

            display dialog "no PDF file located"

        end try

    end tell

    tell application "Adobe Acrobat Pro" to activate

    tell application "Adobe Acrobat Pro"

        set docRefb to the active doc

        bring to front docRefA

        insert pages docRefA after 1 from docRefb starting with 1

    end tell

end tell

------------------------------------- script end

 

Both PDF documents open and are set as the variables docRefA and docRefb, but the acrobat command 'bring to front' and 'insert page' do not seem to be working. I get an error come up in an illustrator dialog box saying "Adobe Acrobat Pro got an error: document "84056_R1.pdf" doesn't understand the bring to front message".


Mac OS X (10.6.8)
  • 1. Re: Combine 2 PDF files into 1 using applescript
    Frank Caggiano Level 7 Level 7 (23,800 points)

    You know you can combine pdf's in Automator with the action Combine PFD pages?

     

    So unless there is an overriding reason to use Applescript and Adobe Acrobat you might want to check that out.

  • 2. Re: Combine 2 PDF files into 1 using applescript
    big_murph Level 1 Level 1 (0 points)

    Thank you for the reply,

     

    Here is a bit of background on the script and its use:

    The script is currently used to produce PDFs in a production environment. Once artwork is complete the user clicks the script and it makes the pdfs and saves them in the correct place to the correct standard. Currently the user then has to combine the PDFs manually, I want to add this process to the current script as a continuation.

    They could use automator but it would actually take longer than dragging and dropping one pdf file into the pages section in acrobat pro, which is what currently happens, so automator wouldnt really help.

     

    The whole point of the script is to make pdfs, then save them, then combine them in one process.

     

    I would really like help with the last part of the applescript please

  • 3. Re: Combine 2 PDF files into 1 using applescript
    twtwtw Level 5 Level 5 (4,690 points)

    in part your script was fubbed and in part Adobe's scripting design is fubbed.  the following script does what you want when you run it, but won't compile in the applescript editor (certain properties and commands, like 'active doc' and 'bring to front' aren't recognized).

     

    set file_path to alias "TMac:Users:tedwrigley:Test area:bibble:"

     

    tell application "Finder"

              set theFiles to (every file of file_path whose name extension is "pdf") as alias list

    end tell

     

    tell application "Adobe Acrobat Pro"

      activate

      open theFiles

     

              set docRefA to document 1

              set docRefb to document 2

      bring to front docRefA

      insert pages docRefA after 1 from docRefb starting with 1 number of pages (count of pages of docRefb)

    end tell

  • 4. Re: Combine 2 PDF files into 1 using applescript
    big_murph Level 1 Level 1 (0 points)

    Hi

     

    Your script get stuck at exactly the same point as mine, thanks for trying though.

     

    Can anyone else help please

  • 5. Re: Combine 2 PDF files into 1 using applescript
    twtwtw Level 5 Level 5 (4,690 points)

    No, you didn't read my response all the way through.  Copy the script into the applescript editor: if you click RUN it works, if you click COMPILE it throws an error.  That's a weird Adobe error.

  • 6. Re: Combine 2 PDF files into 1 using applescript
    big_murph Level 1 Level 1 (0 points)

    My script runs and compiles completely fine. It is just when it hits the adobe acrobat commands that it doesn't work, which is why I am here to see if anyone knows a solution. You posted a different version of a script that does exactly the same thing as mine in a different way and fails at exactly the same point. Thanks for trying though.

  • 7. Re: Combine 2 PDF files into 1 using applescript
    twtwtw Level 5 Level 5 (4,690 points)

    The script works perfectly fine on my machine, with no errors.  If you're getting errors, something's off on your end, not mine.  Now I'm happy to help you work through the problem (look over my other contributions if you think I'm not qualified to do that), but that requires a fair amount of cooperation on your end.  Yes, it's possible that someone else will answer your question on their first try, but that's not the way it usually works. Usually we have to go through a series of exchanges to narrow down the problem.

     

    Unfortunately you've been rude to me twice - "thanks for trying" my proverbial [...] - and that's annoyed me. So if you want my help you you're going to have to ask for it explicitly. If you choose not to, then good luck, and I hope someone else can deliver you a magic bullet.

  • 8. Re: Combine 2 PDF files into 1 using applescript
    big_murph Level 1 Level 1 (0 points)

    I'm really unsure why you are being so nasty but I thought saying 'thank you' to someone for trying to help was a good thing. Probably not best to contribute if you can't do it without being rude to people. As I said before thanks for trying

  • 9. Re: Combine 2 PDF files into 1 using applescript
    BRAVOdirt Level 1 Level 1 (0 points)

    Yeah, but when you say "thanks for trying, can anyone else help please" it comes off a little rude, like ya that didnt work so is there anyone else I can bum an answer off of?

     

    twtwtw took time out of his day to try to help you, in which he gets nothing in return but because it didnt work exactly as you wish you basically just kick him to the curb and on to the next guy (hopefully in your case) cause I dont think your getting anymore help from twtwtw

  • 10. Re: Combine 2 PDF files into 1 using applescript
    twtwtw Level 5 Level 5 (4,690 points)

    Oh, I don't take it personally. I'm mostly annoyed because he's making the process difficult; If he still wants help I'm happy to give it.  But I can't read his mind and I can't see his computer, and I'm not all that inclined to keep guessing at solutions, so...

     

    if he wants this solved he's going to have to come halfway into the conversation and work it through.  Or he can mail me his computer and I'll charge him $500 to get it working just the way he wants. Whichever is good with me. This isn't magic, but some people insist on treating it like it is and it's not really my place to disillusion them. 

  • 11. Re: Combine 2 PDF files into 1 using applescript
    big_murph Level 1 Level 1 (0 points)

    Obviously this being text rather than spoken language, it is difficult to tell the tone of the conversation. I was genuinely saying thankyou for your help, sorry if it offended you it wasn't my intention. I am greatful for any help you can give.

  • 12. Re: Combine 2 PDF files into 1 using applescript
    twtwtw Level 5 Level 5 (4,690 points)

    Fair enough.  so let's check a couple of things. 

     

    1. Which version of Acrobat Pro are you using?
    2. Do you have any third-party scripting additions installed?
    3. Since this block of code appears to be part of a larger script, is it embedded in another tell block, or a script handler, or maybe a script object?  What (in general) happens before you reach this part of the code?

     

    I may have to shift over to my 10.6 partition later to test it there in case it's an OS issue (that's unlikely, but possible), but let's start with this.

  • 13. Re: Combine 2 PDF files into 1 using applescript
    Frank Caggiano Level 7 Level 7 (23,800 points)

    Just seems like overkill.  A single Automator action will do this. Just place the combine pages action in a workflow and call it from the OP's Applescript in place of the Acropbat stuff. Unless Acrobat is doing something extra on the combine?

  • 14. Re: Combine 2 PDF files into 1 using applescript
    twtwtw Level 5 Level 5 (4,690 points)

    I'd tend to agree, except for the one weird factor that he wants to insert document 2 after page 1 of document 1. that would be a headache to accomplish in automator.  plus, the impression I'm getting is that this is one part of a larger script.  both of those conditions make scripting Acrobat Pro seem more palatable.

1 2 Previous Next