Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

automator & applescript

Hi,


I'm looking to automate a process which is splitting a 100+ page PDF into its individual pages then combining them into 2-paged PDF documents. Atm, I am able to split them using applescript to call my automator workflow and have them stored in a folder, then running a simple loop to create subfolders that groups these files into pairs.


Is there a way to call the automator workflow of combine PDFs in a repeat loop for each subfolder? And I'm also not really certain if there is a way to "Get specified finder items" without adding a folder to look into, as I think the solution would depend on this portion of the workflow.


Thank you.

MacBook Pro (Retina, 13-inch, Mid 2014)

Posted on May 4, 2016 8:15 PM

Reply
Question marked as Best reply

Posted on May 5, 2016 9:21 AM

Hi,


You can use an AppleScript to combine PDFs after the "Split PDF" action, like this image:


User uploaded file


Here's the script:

on run {input, parameters}
      set tName to name of (info for item 1 of input)
      set baseName to text 1 thru -6 of tName -- name without the ".pdf" and without the first index
      set tFolder to text 1 thru -((length of tName) + 1) of ((item 1 of input) as string) -- get the path of the folder 
      set tc to count input
      set theOutput to {}
      set j to 1
      repeat with i from 1 to tc by 2
            set firstPDF to quoted form of POSIX path of (item i of input)
            if (i + 1) > tc then
                  set secondPDF to "" -- end of the list, because the number of files is odd
            else
                  set secondPDF to quoted form of POSIX path of (item (i + 1) of input)
            end if
            set newPDF_file to POSIX path of (tFolder & baseName & "_" & j & ".pdf") -- path of the new  2-paged PDF document
            set j to j + 1
            set thesePDF to firstPDF & " " & secondPDF
            -- combine two pdf files & save in the new path  
            do shell script "'/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' --output " & (quoted form of newPDF_file) & space & thesePDF
            set end of theOutput to newPDF_file as POSIX file as alias
      end repeat
      tell application "Finder" to delete input -- delete all PDF's files  (individual page)
      return theOutput -- return the path of the new PDF's files (2-paged) to the next action  
end run
1 reply
Question marked as Best reply

May 5, 2016 9:21 AM in response to klutznic

Hi,


You can use an AppleScript to combine PDFs after the "Split PDF" action, like this image:


User uploaded file


Here's the script:

on run {input, parameters}
      set tName to name of (info for item 1 of input)
      set baseName to text 1 thru -6 of tName -- name without the ".pdf" and without the first index
      set tFolder to text 1 thru -((length of tName) + 1) of ((item 1 of input) as string) -- get the path of the folder 
      set tc to count input
      set theOutput to {}
      set j to 1
      repeat with i from 1 to tc by 2
            set firstPDF to quoted form of POSIX path of (item i of input)
            if (i + 1) > tc then
                  set secondPDF to "" -- end of the list, because the number of files is odd
            else
                  set secondPDF to quoted form of POSIX path of (item (i + 1) of input)
            end if
            set newPDF_file to POSIX path of (tFolder & baseName & "_" & j & ".pdf") -- path of the new  2-paged PDF document
            set j to j + 1
            set thesePDF to firstPDF & " " & secondPDF
            -- combine two pdf files & save in the new path  
            do shell script "'/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' --output " & (quoted form of newPDF_file) & space & thesePDF
            set end of theOutput to newPDF_file as POSIX file as alias
      end repeat
      tell application "Finder" to delete input -- delete all PDF's files  (individual page)
      return theOutput -- return the path of the new PDF's files (2-paged) to the next action  
end run

automator & applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.