Wednesday, September 20, 2017

#1 2015-09-25 10:07:33 am

lotuspixie
Member
Registered: 2015-09-25
Posts: 5

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.


Filed under: PDF, Automator, batch, merge

Offline

 

#2 2015-09-27 07:50:16 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5124

Re: merge same pdf to multiple other pdfs

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?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2015-09-28 04:01:09 pm

lotuspixie
Member
Registered: 2015-09-25
Posts: 5

Re: merge same pdf to multiple other pdfs

I am running Yosemite 10.10.5

Offline

 

#4 2015-09-28 06:29:36 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5124

Re: merge same pdf to multiple other pdfs

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.

Applescript:

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:


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2015-09-29 09:38:49 am

lotuspixie
Member
Registered: 2015-09-25
Posts: 5

Re: merge same pdf to multiple other pdfs

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.

Offline

 

#6 2015-09-29 06:43:54 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5124

Re: merge same pdf to multiple other pdfs

Were these documents you'd dowloaded from somewhere?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#7 2015-09-29 08:50:07 pm

lotuspixie
Member
Registered: 2015-09-25
Posts: 5

Re: merge same pdf to multiple other pdfs

Yes, downloaded from Moodle, our course management system.

Offline

 

#8 2015-09-29 11:45:41 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5124

Re: merge same pdf to multiple other pdfs

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#9 2015-09-30 08:32:41 am

lotuspixie
Member
Registered: 2015-09-25
Posts: 5

Re: merge same pdf to multiple other pdfs

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

Offline

 

#10 2015-11-01 07:08:54 am

ccstone
Member
Registered: 2009-02-07
Posts: 409

Re: merge same pdf to multiple other pdfs

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

Applescript:


-------------------------------------------------------------------------------------------
# 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 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Offline

 

#11 2015-11-01 07:29:12 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5124

Re: merge same pdf to multiple other pdfs

ccstone wrote:

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


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?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)