Combine PDFs

Hi there,

following situation:
There are 2 different folders, FP (Frontpage) and OG (Original)
In FP you can find pdfs, namerange from 100.pdf to 10000.pdf
In OG you can find the same, but not all of them - so maybe 105-195 is non existent, 200.pdf is again there.

Now I want to combine those 2 pdfs - of course FP at first, OG at second.

I started with Automator and a Folder Action, but there I cannot get the name of the input file (f.e. 102.pdf) to then grab the specific 102.pdf in the FP folder - the exact point there is that the aciton “Find Finder Item” does not accept Variables as Input-Pattern for a search.

With applescript I went to get a proper dir-listing of OG, but then again I am unable to get again the specific pdf from FP to then give that AND the OG-file as Input for the action “Combine PDFs” in Automator. (see http://stackoverflow.com/questions/2097263/get-full-directory-contents-with-applescript)

I am new to applescript / automator but I got a bit of programming knowledge (3-years apprenticeship, but its been a while).

Of course it is mindbogglingly easy to combine the pdfs manually - just open preview and drag’n’drop. Since there are about 200 files, I would love to have an automated scriptly for that.

Thanks in advance for any ideas / suggestions!!

Cheers,
Sam

P.S. I started a topic on that at mac-help.com - to stop all those “you post multiple times blubb”-guys. :slight_smile:

P.P.S. With this http://macscripter.net/viewtopic.php?id=33789 maybe I get a bit further - there is an excel-file with all the numbers anyway.

So I think I might be done with a way how to pass on the 2 files to combine pdf somehow … Is there a way to start a loop in a “run applescript”-action, proceed with combine pdfs and close the loop again afterwards with “run applescript” ?

Ok, I am getting there.

Here’s what I’ve got:

tell application “Microsoft Excel”
set theCells to value of range “B3:B4” of active sheet
end tell

– set ogpath to “:Users:sam:Dropbox-personal:Dropbox:Skripten_Intern:Testsystem PDF:OG:”
– set fppath to “:Users:sam:Dropbox-personal:Dropbox:Skripten_Intern:Testsystem PDF:FP:”
– set outputpath to “:Users:sam:Dropbox-personal:Dropbox:Skripten_Intern:Testsystem PDF:PRINT:”

repeat with oneCell in theCells
tell application “Finder”
display dialog “/Users/sam/Skripten/PRINT/” & oneCell & “.pdf”
end tell
– do shell script “python ‘/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py’ -o '/Users/sam/Skripten/PRINT/” & oneCell & “.pdf’ '/Users/sam/Skripten/FP/” & oneCell & “.pdf’ '/Users/sam/Skripten/OG/” & oneCell & “.pdf’”
– do shell script “python ‘/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py’ -o '” & outputpath & oneCell & “’ '” & fppath & oneCell & “’ '” & ogpath & oneCell & “'”
end repeat

As you can see, my paths get quiet stupid. For that, I wanted to display the string I’d like to give python.

Unfortunately, oneCell seems to have the value 100,0 101,0 etc, eventhough I formatted the cells in excel to have no decimal numbers.

Soooooo … The last problem I have, is to somehow construct a path to look like

/Users/sam/Skripten//100.pdf

Of course with 100,0 and so on I get empty pdfs.

Can somebody tell me please how to make oneCell a int (afaik, this would be the way?) ?

Thanks!!

Sam

Well well, this time in a working condition, with proper formattig and comments what its doin.


-- get needed input from excel
tell application "Microsoft Excel"
	set theCells to value of range "B13:B17" of active sheet
end tell

-- configure the paths
-- fp = 1st pdf
-- og = 2nd pdf

set fppath to "/Users/sam/Dropbox-personal/Dropbox/Skripten_Intern/auto/FP/"
set ogpath to "/Users/sam/Dropbox-personal/Dropbox/Skripten_Intern/auto/OG/"
set outputpath to "/Users/sam/Dropbox-personal/Dropbox/Skripten_Intern/auto/PRINT/"

repeat with oneCell in theCells
	set skript to oneCell as integer
	
	-- for debug-purposes: display our pathes
	-- tell application "Finder"
	-- display dialog "fppath: " & fppath & " OGPATH: " & ogpath & " OUTPUT: " & outputpath
	-- end tell
	
	-- do it then
	do shell script "python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o '" & outputpath & skript & ".pdf' '" & fppath & skript & ".pdf' '" & ogpath & skript & ".pdf'"
end repeat

I will try to figure out how to handle errors coming from python, because at this stage it produces a .pdf - doesn’t matter if there is a pdf to combine with or not.

That should be a not too hard step. Finally, I am getting somewhere. :slight_smile:

So in case anyone finds time to help with that or improve coding in general, please feel welcome to contribute. :slight_smile:

Ok, shitty code but for google here it is:

-- get all possible numbers from excel
tell application "Microsoft Excel"
	set theCells to value of range "B25:B29" of active sheet
end tell

-- configure the paths
-- fp = 1st pdf
-- og = 2nd pdf

set fppath to "/Users/sam/Dropbox-personal/Dropbox/Skripten_Intern/auto/FP/"
set ogpath to "/Users/sam/Dropbox-personal/Dropbox/Skripten_Intern/auto/OG/"
set outputpath to "/Users/sam/Dropbox-personal/Dropbox/Skripten_Intern/auto/PRINT/"

repeat with oneCell in theCells
	
	set skript to oneCell as integer
	set fp to fppath & skript & ".pdf"
	set og to ogpath & skript & ".pdf"
	
	-- couldnt do it without conversion for the try
	set foo to POSIX file fp
	set bar to POSIX file og
	
	try
		foo as alias
		bar as alias
		-- do it then
		do shell script "python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o '" & outputpath & skript & ".pdf' '" & fp & "' '" & og & "'"
		--tell application "Finder"
		--	display dialog "python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o '" & outputpath & skript & ".pdf' '" & fp & "' '" & og & "'"
		--end tell
	on error
		display dialog "Fehler: " & fp & " does not exist " & og
	end try
end repeat