Mac Automator to create separate pdfs for each folderq

ratboy90

macrumors 6502
Original poster
Apr 15, 2009
321
7
I want to use automator to create a pdf from a set of images each in a separate folder. So folder a - pdf a/folder b - pdf b and so on...

I can't seem to get automator to do this. Can anyone help me out?
 

kryten2

macrumors 6502a
Mar 17, 2012
999
60
Belgium
Try this :

  1. Make Automator worflow with New PDF from Images action. OutputFolder is variable!
  2. Open Script Editor and copy the following script into it. Change the set workflowpath line. Run the script

Caution : No spaces in foldernames or filenames! Couldn't find a solution to that.

Code:
-- change line below to the right name and location where you saved your .workflow
set workflowpath to "LeopardFirewire:Users:test:Desktop:New PDF from Images.workflow"
set qtdworkflowpath to quoted form of (POSIX path of workflowpath)
set theExtensionList to {"jpg", "png", "tiff", "pdf"}
set theFolders to choose folder with multiple selections allowed
repeat with aFolder in theFolders
	set theInputList to {}
	tell application "Finder" to set theFoldersContents to (every item of aFolder whose name extension is in the theExtensionList) as alias list
	repeat with anItem in theFoldersContents
		set end of theInputList to quoted form of POSIX path of anItem
	end repeat
	set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
	set theInputList to theInputList as text
	set AppleScript's text item delimiters to tid
	set command to "/usr/bin/automator -v " & "-i '" & theInputList & "' -D OutputFolder=" & quoted form of POSIX path of aFolder & " " & qtdworkflowpath
	set output to do shell script command
end repeat
return output
Another script : Spaces in foldernames or filenames allowed

Code:
set theFolders to choose folder with multiple selections allowed
repeat with aFolder in theFolders
	tell application "Finder"
		if not (exists folder "OutputFolder" of aFolder) then
			set theOutputfolder to (make new folder at aFolder with properties {name:"OutputFolder"}) as alias
		end if
	end tell
	set command to "cd " & quoted form of POSIX path of aFolder & ";" & "sips -s format pdf *.{jpg,tiff,png,pdf} --out " & "OutputFolder"
	set theCombiningPDFcommand to "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py -o " & quoted form of POSIX path of theOutputfolder & "Combined.pdf" & space & quoted form of POSIX path of theOutputfolder & "*.pdf"
	do shell script command
	delay 1
	do shell script theCombiningPDFcommand
	delay 1
	tell application "Finder" to delete (every item in folder theOutputfolder whose name is not "Combined.pdf")
	tell application "Finder" to empty
end repeat
 

Attachments

Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.