merge same pdf to multiple other pdfs

I’m hoping you can help solve a workflow problem that I have. I’m an automator novice but have played around with it and haven’t yet found a solution to my problem.

I’d like to write an automator script that will take one specified pdf and merge it to each pdf in a separate specified set.

In more concrete terms: I’m a professor with lots of grading to do. I’ve “gone electronic” with my assignment submissions, but I want a way to quickly add my rubric page (single page pdf) to the beginning of each of my students’ assignments.

Thank you for your help, and let me know if I can provide further details.

I don’t think that’s directly do-able via Automator, but there might be another way. What version of the OS are you running?

I am running Yosemite 10.10.5

OK, then what you want can be done via AppleScript. Save the following script from Script Editor as an Application. Then drag the PDFs you want to add the pages to over the application; you will be asked to select the cover-page PDF.

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "Quartz"

on open fileList -- drag list of PDFs to be updated
	set masterFile to POSIX path of (choose file with prompt "Choose the master file:" of type {"pdf"})
	set listOfPosixPaths to {}
	repeat with aFile in fileList
		set end of listOfPosixPaths to POSIX path of aFile
	end repeat
	my insertPageOneFrom:masterFile intoDocuments:listOfPosixPaths
	display dialog "Finished" buttons {"OK"}
end open

on insertPageOneFrom:posixPath intoDocuments:listOfPosixPaths
	set theURL to current application's class "NSURL"'s fileURLWithPath:posixPath
	set thePDFDoc to current application's PDFDocument's alloc()'s initWithURL:theURL
	set thePage to thePDFDoc's pageAtIndex:0 -- zero-based
	repeat with aPath in listOfPosixPaths
		set thisURL to (current application's class "NSURL"'s fileURLWithPath:aPath)
		set oldName to (thisURL's lastPathComponent()'s stringByDeletingPathExtension()'s stringByAppendingString:"+")
		set newURL to ((thisURL's URLByDeletingLastPathComponent()'s URLByAppendingPathComponent:oldName)'s URLByAppendingPathExtension:"pdf")
		set thisPDFDoc to (current application's PDFDocument's alloc()'s initWithURL:thisURL)
		(thisPDFDoc's insertPage:thePage atIndex:0)
		(thisPDFDoc's writeToURL:newURL)
	end repeat
end insertPageOneFrom:intoDocuments:

Thank you. This works. One issue: the first couple times I dragged a set of 14 files onto the application, it only added the cover page to three of them. I did it again with the 11 that it didn’t append the first time, and it again added it to only three of them. Then I dragged the last eight and this time it added the cover page to all of them.

Were these documents you’d dowloaded from somewhere?

Yes, downloaded from Moodle, our course management system.

OK, the problem you are seeing stems from the fact that the files have their quarantine bit set. All droplets have the same problem. If you open them and close them first, they should all process fine.

Wonderful. I’ll do that. Thank you so much for your help help with this!

Opening many files to de-quarantine them is a bore.


-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2012/07/01 14:04
# dMod: 2015/09/03 09:56
# Appl: Finder & Shell
# Task: Turn off the Quarantine-bit of the files in the front Finder window.
# Osax: None
# Libs: ELb
# Tags: @Applescript, @Finder, @Quarantine, @De-Quarantine
-------------------------------------------------------------------------------------------

try
	
	set fileSelector to "*"
	
	tell application "Finder"
		if window 1 exists then
			set _win1 to target of front window as string
		else
			error "No windows are open!"
		end if
	end tell
	
	set _win1 to quoted form of (POSIX path of _win1)
	
	set shCMD to "cd " & _win1 & ";
	xattr -d com.apple.quarantine " & fileSelector & ";
	exit 0;"
	
	do shell script shCMD without altering line endings
	
on error e number n
	stdErr(e, n, true, true) of me
end try

-------------------------------------------------------------------------------------------


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

It is. But clearing them by the folder-load strikes me as a tad permissive; wouldn’t it be safer to operate just on the selection?

Hi, I found this very interesting script, but I need a modification for my purposes:

this script just add a single-page pdf at the top of each pdfs.
How can I modify to add a multiple-pages pdf at the top of each pdfs?
And how to add at the bottom of each pdfs?

Thanks a lot