Applescript equivalent of Automator's "Combine PDF"?

Folks -
I'm starting to learn Applescript, and working to use it to help automate some workflows in a prepress department.
I'm trying to write a script that (among other things) will combine a folder full of PDFs into one file before passing it along to the next step. This is easy using Automator, but the only Applescript equivalent that I've found calls for Acrobat to launch and combine the files - this seems to run more slowly than the Automator version, which doesn't appear to call Acrobat at all. I thought I'd try scripting Preview to do the same thing, but I didn't realize that Preview isn't scriptable.
Is there a way I can accomplish this without combining Automator and Applescript, or am I out of luck? (I have a sneaking suspicion that this may involve a shell script, which would mean that I'm out of my depth.)
Thanks for any ides on this one..
-Andy Gill

Hi Andy,
I thought I'd try scripting Preview to do the same thing, but I didn't realize that Preview isn't scriptable.
Using [GUI Scripting|http://www.macosxautomation.com/applescript/uiscripting/index.html], it should be relatively easy to write a script that will do what you are asking for. The drawback, however, is that such a script would have to open Preview.app and so could not run inconspicuously in the background.
Maybe you might want to have a look at these two Mac OS X Hints articles:
[10.5: Use Preview to merge or create multi-page PDFs|http://www.macosxhints.com/article.php?story=20071114191806624]
[10.6: Combining documents in Snow Leopard's Preview|http://www.macosxhints.com/article.php?story=20090915223224601]
Hope it can help.

Similar Messages

  • Getting File Name in Automator workflow - combine PDF

    I am using Automator to combine 2 PDF files.
    I would like to inherit one of the file names in the new PDF and append a standard text to the front of the file name.
    I am not sure how to do this. I can combine the PDFs the way I would like, but I am not sure how to plick the file name.
    my workflow is as follows.
    Folder Action targets folder where 1st PDF is added(I want this FILE NAME).
    Ger Specified finder item selects 2nd PDF to be combined.
    Sort Finder Items makes sure the new PDF pages are ordered properly.
    Combine PDF Pages combines the pages.
    Move Finder Items saves the files where i want it.
    Name single item is whre i thought to add my standard text plus the variable of FILE NAME.
    Open File in mail to set up my email.
    Anyone can help with this?
    thanks,
    Aaron

    Here is an automator workflow that does something similar so I believe you can adapt to your needs.  This workflow is setup as a service workflow. It will combine PDFs in the order in which they are selected/clicked via the Shift key.  The default name of the combined output file will be the name of the first file clicked.  Automator can be activated by CTRL clicking any of the selected PDFs.
    1. Service receives PDF files in Finder
    2. Automator Action: Run AppleScript
    on run {input, parameters}
              display dialog "Files will be combined in the order selected via the Shift key" as text
              return input
    end run
    3.. Automator Action: Trim input items
    keep the first one
    you will need to download and install this autotmator action from here:
    http://www.menace-enterprises.com/Files/Automator/Actions/Trim%20Input%20Items.d mg
    4.  Automator Action: Run AppleScript
    (* Note & Definitions
    This Applescript extracts the basename of the first selected file without its .pdf extension
    "path_basename_ext" is full path and name, e.g. User/desktop/file.pdf
    "NmExt" is filename with extension, e.g. file.pdf
    "baseName" is the base filename without extension, e.g. file
    "Ext" is the file's extension, e.g. pdf
    on run {input, parameters}
              set path_basename_ext to input
              tell (info for path_basename_ext) to set {NmExt, Ext} to {name, name extension}
              set baseName to text 1 thru ((get offset of "." & Ext in NmExt) - 1) of NmExt
      baseName
              return baseName
    end run
    5.  Automator Action: Set Value of Variable
    define baseName as the variable
    6.  Automator Action: Get selected finder items
    Options: check ignore input
    7. Automator Action: Combine PDF pages
    choose Combine by appending
    8. Automator Action: Move Finder Items
    choose To: Desktop
    Options: check show this action when workflow runs
    9. Name Single Items
    choose Basename only to: baseName
    Options: check show this action when workflow runs
    10. Open Finder Items

  • Automator Service: Combine PDFs Then Delete Originals

    Hello All,
    I've managed to create a service using Automator that combines PDF files, renames the newly created file, and moves it (http://www.documentsnap.com/how-to-combine-pdf-files-in-mac-osx-using-automator- to-make-a-service/).
    What I am now trying to figure out is how I could have automator prompt me at the end to ask if I'd like to move the original files (PDFs) to the trash, and then do so upon confirmation. I haven't had any luck figuring this out on my own.
    Does anyone out there know if this is possible?
    Thanks!

    sure, it's possible.  what you need to do is:
    add in a Set Value of Variable action right at the beginning
    at the end, add in an Ask for Confirmation action that asks if they want to delete the original files.
    after that add in a Get Value of Variable action for the variable in step 1
    then add a Move Finder Items to Trash action
    first step stores the passed-in file references in a variable for later use, and passes them on to your script.  the second step gets user input, stopping the workflow if the user cancels.  the third step recovers the file references stored at the first step, and the last step deletes the files.

  • Bug in Automator's Combine PDF Pages action?

    Hi guys,
    I've been playing around with 10.6's new Automator and Services. I decided to make an Automator Service so that if I have some PDFs selected in Finder, I can combine all the pages into one PDF and save it to a location. So I created the following service:
    * Get Selected Finder Items
    * Combine PDF Pages (appending pages)
    * Move Finder Items (to Desktop by default, show this action when the workflow runs)
    * Rename file (comes up as Name Single Item in Finder Item Names, show this action when the workflow runs)
    I tested this in Automator by selecting some PDFs on my desktop and hitting the Run button; everything worked out well. So I saved it as an Automator Service, only available for PDF files but in all applications (drop down lists at the top of the Automator window).
    I noticed however when I ran this workflow as a service, the pages in the resulting PDF file is actually duplicated. For example, if I had page 1 in page1.pdf, and page 2 in page2.pdf, running the service on these two files will produce a PDF with the following pages: page 1, page 2, page 1, page 2.
    Does this happen to anyone else in here, or is it just me? I tried saving the workflow as an application, placed it in the Dock, and then dropped my test files on it and it does the same thing. And this happens with other PDF files too.
    Is this a bug? Can someone confirm that it happens on their machine too?
    Thanks.

    Anyone? It doesn't take long to create an Automator workflow with the 4 actions above. Probably 2 minutes max. Can someone test on their machine?
    I tried to do the same with my MBP, which I also upgraded to Snow Leopard, and it does the same thing there. For some reason, it works perfectly when the workflow is run within Automator, but when it's exported as an Application or a Service, it duplicates pages.
    I tried to submit a bug report to Apple, but I couldn't log in with my current Apple ID -- it shows me an error page to submit a bug report! That's what I've been trying to do in the first place, but it seems the bug report process has bugs that they want you to report on. Chicken and egg scenario methinks.

  • "Combine PDFs" Places New File In /private/var/folders/0Q etc. WHERE?

    I have just used Automator to combine .pdfs.
    Apparently it has put the combined file in ....
    /private/var/folders/0Q/0QlZ-reFFvSsYn6CVY8VXk+Ti/-Tmp-/ftqdhY.pdf
    So where on earth is that?
    I can summon up the new file by double-clicking it in the Automator "Results" window and save it somewhere convenient, but I would like to be able to drag the original from where it is hiding and put it in a place of my choosing.

    Thanks! The nearest I could find to your suggested action was "New Folder", which I didn't hold out much hope for, but it worked!
    Any idea how to access the weird place my original attempts were put into?

  • Combine PDF Pages automator step strips annotations

    Oh, I was so excited when I noticed the Combine PDF Pages command in Automator.
    Then I was less excited when I discovered that if any of the pages has annotations created in Acrobat Pro, those annotations are removed from the newly combined PDF.
    Since Preview, for some strange reason, is not AppleScript-able, Automator is the only way I see to do this.
    Acrobat is somewhat scriptable to a degree but does not have a combine PDFs command in the dictionary.
    So, has anyone figured out a way to automate the merging of PDFs via a script, workflow, app, etc -- while RETAINING the annotations? I am triggering this from FileMaker as part of a work process we're developing, so manually merging the PDFs kind of defeats the purpose.
    Anyone have any suggestions?
    Thanks,
    Jeff

    Found It!
    Ok, so it seems "insert pages" is in the Acrobat dictionary; I was looking for an equivelant of "Combine Files into Single PDF".  Anyway, here's draft one of the script. I'll probably make it less clunky next week, but this is basically how it works:
    set nFile to ""
    set pCount to 0
    set pdfList to {}
    set pdfNameList to {}
    set sourcePath to "SL:Users:joeuser:Desktop:fix ccd:Source:"
    set targetPath to "SL:Users:joeuser:Desktop:fix ccd:Target:"
    set coverFileName to "cover.pdf"
    tell application "Finder"
    move file (sourcePath & coverFileName) to folder targetPath
              set my pdfList to every file in folder sourcePath
              repeat with f in pdfList
                        set pdfNameList to pdfNameList & (name of f)
              end repeat
    end tell
    tell application "Adobe Acrobat Pro"
    --activate
    open (my targetPath & my coverFileName) with invisible
              set targetDoc to last document
              set my pCount to (number of pages) of targetDoc
              get my pdfNameList
              repeat with f in my pdfNameList
                        set c to number of documents
                        open (sourcePath & f) with invisible
                        repeat until c < (number of documents)
                        end repeat
                        set newDoc to last document
                        set nPages to (number of pages) of newDoc
      insert pages targetDoc after my pCount from newDoc starting with 1 number of pages nPages
                        set my pCount to (my pCount) + nPages
      close newDoc
              end repeat
    save targetDoc
    close targetDoc
    end tell
    tell application "Finder"
              set f to file (my targetPath & my coverFileName)
              set name of f to "New Merges PDF.pdf"
    end tell

  • Combine PDF trough Automator

    How do I combine PDF's trough the Automator - Step for Step.... thx alot
    Greets Simon

    Simply double-click or drag the "Combine PDF Pages" action from the "PDF" action library into your workflow. Then do the same for Finder's "Open Finder Items" action. Click File > Save As Plug-in, give it a name, confirm that it's a plug-in for Finder, and click Save.
    Now whenever you control-click on a selected group of PDFs in Finder, you can click Automator > [your workflow] and it will open them as a combined document.

  • Applescript Acrobat combine pdfs

    Hi,
    I've tried and failed to create a script that takes two PDF files I've selected in the finder, open Acrobat Pro and use the Combine feature (File > Combine > Merge Files into a Single PDF...), saving them out with the filename taken from the clipboard.
    The Automator combine pdfs application and other off-the-shelf products are no good to me as they rely upon choosing files from a dialog box, and the fonts in the resulting pdf can also become corrupted.
    So if I go to the Finder and select a file, copy its name, then select a second file, I want a script to combine these two selected PDFs into one, using Acrobat. The filename becomes the name of the first file I copied.
    Can anyone help? Many, many thanks if you can: I have a few hundred of these to do.

    JustinR wrote:
    So if I go to the Finder and select a file, copy its name, then select a second file, I want a script to combine these two selected PDFs into one, using Acrobat. The filename becomes the name of the first file I copied.
    Can anyone help?
    I don't use Acrobat. Nevertheless, the following script should do exactly what you are asking for using Preview.app. instead.
    set theTitle to (the clipboard) & "*" -- remove the asterisk if you wish
    set theApp to POSIX file "/Applications/Preview.app" as alias
    tell application "Finder"
        set S to selection
        if S is {} then return
        repeat with thisItem in items of S
            if not (name extension of thisItem is "pdf") then return
        end repeat
        open S using theApp
    end tell
    tell application "Preview" to activate
    tell application "System Events" to tell process "Preview"
        set windowName to name of window 1
        tell menu 1 of menu item "Sidebar" of menu 1 of menu bar item "View" of menu bar 1
            if menu item "Hide Sidebar" exists then click menu item "Hide Sidebar"
            click menu item "Show Sidebar"
        end tell
        keystroke "a" using {command down} -- Select All
        keystroke "p" using {option down, command down} -- Print Selected Pages…
        repeat until sheet 1 of window 1 exists
            delay 0.1
        end repeat
        click menu button "PDF" of sheet 1 of window 1
        click menu item "Save as PDF…" of menu 1 of menu button "PDF" of sheet 1 of window 1
        keystroke theTitle
        keystroke "d" using command down
        keystroke return
        if button "Replace" of sheet 1 of window "Save" exists then
            click button "Replace" of sheet 1 of window "Save"
        end if
        repeat while sheet 1 of window windowName exists
            delay 0.1
        end repeat
        keystroke "w" using {command down}
        set destinationFolder to choose folder with prompt "Where to put the merge PDF ?" default location (path to home folder)
    end tell
    tell application "Finder" to move file theTitle of desktop to destinationFolder with replacing
    Hope it can help.
    Message was edited by: Pierre L.

  • Trying to create a "Combine PDF" that also has a "save as" dialog box

    I am able to get the Combine PDF to work but it just saves them as randomly named files on the desktop that I then need to rename manually. Is there some way to make a "save as" dialog box pop up after combining the files? So if I had a bunch of PDFs it would go:
    Right Click on selected files > Automator > Combine PDF > Save As
    Is this possible?

    Set up you worflow as:
    Get Selected Finder Items
    Combine PDF Pages
    Open Images in Preview
    Run Applescript
    +copy this into the Applescript box+
    tell app "System Events"
    keystroke "s" using {command down, shift down}
    keystroke "d" using {command down}
    end tell
    I also like to add a Sort Finder Items after the Get Selected Finder Items.

  • 2Sided Original 1Sided ADF Scanner -Combine PDF Pages -  Data Error?

    I just purchased a scanner with an Auto Document Feeder, ADF, of 25 pages after trying to use it I found out through the company that it only scans one side. I have another ADF scanner where the software allows the user to flip the pages over and then reinserts them for the final PDF file. Instead of spending more on a double sided scanner I figured I would create a program using Automator.
    The script I created worked a few times but after some tweaking it stopped.
    The problem is just before the Combine PDF Pages where I have two "Get Value of Variables" which I set as PDF Documents at the beginning of the script.
    The log reads before and at the point of error;
    Conversion from Files/Folders (com.apple.applescript.alias-object) to PDF files com.apple.applescript.alias-object.pdf) completed.
    . ! The action "Combine PDF Pages" was not supplied with the required data.
    The variables are showing the entire path to include the filename and extention of my selected PDFs, but the log above the error seems to change the variable to the appropriately desired object.
    ? What I need to do to correct this error because it seemed to work earlier by using variables?
    The script would be useful for any type of ADF scanner that outputs one-sided to PDFs and the originals are two-sided.
    Your help is appreciated.
    KGz
    Message was edited by: KGz

    Red
    I have been working in Automator for this program and saved it as an Applescript plug-in for the Scripts Menu. I don't have to have it as a script I just need it to work.
    The pecular thing was while testing the program in Automator before exporting it to the plug-in the program was skitish meaning that at first it didn't work then I added 'view results' and then afterwards it seemed to work. After this I removed 'view results' and it worked then I exported it but since then I can't get it to work again even after reinserting 'view results'.

  • Combine PDFs using Preview in Mountain Lion (other threads read)

    I have reviewed several threads about combining PDFs in Mountain Lion.  I will ultimately learn Automator but for now, I have a relatively simple question:
    1) I open multiple PDFs in Preview, one window per PDF
    2) I drag thumbnail pages from documents 2 through n onto document 1 so that it makes one long document.  ie. one unbroken string of pages and not sections within a PDF
    Question:  How do I save this combined document without deleting or affecting the first document?
    Duplicate causes one of the uncombined documents to pop up with the filename highlighted.  I don't see how to give the combined document a new filename for saning
    Rename gives me a file of the three combined documents but the first document disappears
    Save overwrites the first document with the combined document
    I must be missing something simple.  I recognize that the lack of "Save As" is a sensitive issue but ultimately, that's what I want to do:  Save the combined document with its own filename and have the individual documents intact.

    ncasey88 and Old Toad:
    Thank you for your quick responses.  Unfortunately, with both methods, the first PDF gets updated.
    e.g. Files are 1.pdf, 2.pdf, 3.pdf, each is one page long, and I open each in its own Preview window.  I drop thumbnails of 2.pdf and 3.pdf onto the thumbnail area of 1.pdf.  I export or print into a file called 123.pdf 
    Result:  1.pdf and 123.pdf have the same information (all three files).  2.pdf and 3.pdf are unchanged but 1.pdf is three pages long.

  • Combine PDFs with a script

    I want to create a script, either AppleScript or JavaScript, that automatically combines all PDFs that are open in Acrobat Pro, then saves and closes the new binder. I'd also like to specify location of the saved binder.
    If that is possible, it may be possible to do it without opening any PDFs, just specifying which files to combine. That would save time not having to open any PDFs

    Consider using an external script, especially since I don't know how you'd do this with batch processing (aka Action) within Acrobat. For example, a VBScript/JScript could loop through the files in a directory, determine which files need to be combined, and use IAC (InterApplication Communications) with Acrobat to do the combining. Then save each new file to the appropriate directory. For more information on IAC, download the Acrobat SDK. There is an Acrobat SDK forum here where you can ask more questions.

  • Combining PDF's in Adobe Standard Xi

    When I combine PDF files with Standard Xi, the new combined PDF is missing text all of the place.
    Any suggestions?

    Just wanted to say Thank You to Jeffery for his post which solved my Problem!! One thing to note however: The show file result window in this action for some reason is not visible, so allthough the action does work you cant find your File!
    After some more looking in the Automator forum I found the answer from
    Alan Pearson.
    The combined file is hiding in : /private/tmp
    Thanks again all

  • Combine PDF files into one document?

    Hi, does anyone know if there is a way to take several PDF documents that are the same size and orientation and combine them into one file?
    Thank you,

    Hi,
    there's sadly no such function in Mac OS, but you can do it for free with Automator. There's a "Combine PDFs" function. I saved it as an application. If you can't figure it out, I can upload you the app, but Automator is really straightforward.
    Björn

  • Need help creating applescript to perform automator actions.

    Hi,
    I am looking for help with an applescript the will tell automator to execute  the steps of a workflow.  I'm aware that I coud just run a workflow or even tell applescript to instruct automator to run the workflow, however, I am looking to make this part of a larger workflow and this method would save the hassel of having to create a new workflow outside of applescript each time.
    I would like automator to "get folder contents" then "extract pdf text" to a "new file" with the "same name as original file" in the "same location as original" and "save as txt".  This doesnt seem to difficult to me, however, I have limited knowledge of scripting at this time.
    I appreciate anyones help...

    Hi,
    I'd say on a difficulty scale of 1-10, what you're asking for is a seven.
    Automator is scriptable, but when you run a basic AppleScript like
    tell application "Automator" to make new workflow
    you immediately get taken to the dialog asking you to choose a type for your document (app, calendar plugin etc). So that's going to stop the AppleScript dead in its tracks. It might be possible to move on with GUI scripting (using AppleScript to click the buttons) but it would be a ferocious cludge.
    I think the best approach would be to manually create an empty action as a starting point. You would then need an AppleScript that would duplicate the workflow file (so you've got a fresh one to duplicate next time), open it in Automator, add the appropriate actions, set the settings etc.
    It all sounds a bit too complicated
    HD

Maybe you are looking for