Author Topic: Tweaking Script to Batch Process PDFs in Quark  (Read 1214 times)

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Tweaking Script to Batch Process PDFs in Quark
« on: May 05, 2015, 03:02:03 PM »
Thanks to the wonderful people on these forums, I figured out how to create a script that batch processes quark files into pdf files.  It does work well, but the number of pages I have to batch process varies. Sometimes I would be dropping 12 files. Other times I would be dropping anywhere from 4 to 10 files. I was wondering if there was a way to process this so I don't have to copy and paste the same line of code 4-12 times and change the project number for each line? Can Quark open and pdf each file without me having to specify that this is project 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12...?

Thanks for your help!


Here's a sample of the script I used for creating pdfs of 4 files:

on open droppedfile
   tell application "QuarkXPress"
      activate
      open droppedfile
      export layout space 1 of project 1 in ("path of file:" & name of project 1 & ".pdf") as "PDF" PDF output style "Quad PDF"
      export layout space 1 of project 2 in ("path of file:" & name of project 2 & ".pdf") as "PDF" PDF output style "Quad PDF"
      export layout space 1 of project 3 in ("path of file:" & name of project 3 & ".pdf") as "PDF" PDF output style "Quad PDF"
      export layout space 1 of project 4 in ("path of file:" & name of project 4 & ".pdf") as "PDF" PDF output style "Quad PDF"
      close every project saving no
   end tell
end open

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Tweaking Script to Batch Process PDFs in Quark
« Reply #1 on: May 06, 2015, 03:44:36 AM »
Hi! This is typically why the loop was made for.
You should have sth like this running fine:
Code: [Select]
on open droppedfile
tell application "QuarkXPress" to activate
repeat with afile in droppedfile   
tell application "QuarkXPress"
      open afile
      export layout space 1 of project 1 in ("path of file:" & name of project 1 & ".pdf") as "PDF" PDF output style "Quad PDF"
      close project 1 saving no --here, #1 means the frontmost project in Quark
   end tell
end open
Tell me if anything is going wrong.
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Tweaking Script to Batch Process PDFs in Quark
« Reply #2 on: May 07, 2015, 02:06:31 PM »
That works great! Thanks Jean-Marie. :)

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Tweaking Script to Batch Process PDFs in Quark
« Reply #3 on: May 19, 2015, 11:18:58 AM »
I tweaked the script a little bit. What this does is create a pdf file of only the first spread in each file and it removes the .qxp from the pdf filename.  Before my files were named something like 1-8 4dayfd15 6854 prep.qxp (Page 01).pdf. Now the filename is coming through as 1-8 4dayfd15 6854 prep (Page 01).pdf

I hope this script is able to help someone else just like other people's scripts helped me.  If you need more than just the first spread simply change export spread 1 of document 1 to export document 1.

on open droppedfile
--Change "path of your file:" to the valid path for your particular file
   set my_destination to "path of your file:"
   tell application "QuarkXPress" to activate
   repeat with afile in droppedfile
      tell application "QuarkXPress"
         open afile
         set doc_name to get name of document 1 as string
--Change "Quad PDF" to the name of your pdf output style
         export spread 1 of document 1 in (my_destination & (characters 1 thru -5 of doc_name) & ".pdf") as "PDF" PDF output style "Quad PDF"
         close document 1 saving no
      end tell
   end repeat
end open
« Last Edit: May 19, 2015, 11:22:23 AM by mbornbach »

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Tweaking Script to Batch Process PDFs in Quark
« Reply #4 on: June 11, 2015, 10:49:29 AM »
Tweaked it some more:

Now it:
-Creates a pdf file of just the first 2 pages of each document dropped onto the applescript droplet
-Creates a new subfolder named "PDFs" within the folder that the quark files are in if that subfolder doesn't already exist
-Moves the pdf files into the "PDFs" subfolder, replacing any old pdf files in that folder with the same filename

Code: [Select]
on open of droppedfiles
tell application "QuarkXPress" to activate
repeat with afile in droppedfiles

--TELLING QUARK TO CREATE PDF FILES
tell application "QuarkXPress"
open afile
set my_destination to file path of document 1 as string
set doc_name to get (characters 1 thru -5) of my_destination as string
export document 1 in (doc_name & ".pdf") as "PDF" page range "1, 2" PDF output style "Quad PDF" --Change Quad PDF to name of your pdf output style
close document 1 saving no

--CREATING PDFs FOLDER IF IT DOESN'T EXIST YET
set parentFolder to my getParentFolder(afile)
set newFolder to (parentFolder as text) & ":"
if not my CheckForFolder(parentFolder & "PDFs:") then
tell application "Finder"
set subFolder to (make new folder at folder parentFolder with properties {name:"PDFs"})
end tell
end if
end tell
end repeat

--MOVING PDF FILES INTO THE PDFs FOLDER
tell application "Finder"
set subFolder to (folder "PDFs" of folder parentFolder)
move (files of folder parentFolder whose name extension is "pdf") to subFolder with replacing
end tell
end open

on getParentFolder(filePath)
set folderParts to my GetTextItem(filePath as text, ":", {1, -2})
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set parentFolder to folderParts as text
set AppleScript's text item delimiters to OldDelims

return (parentFolder & ":") as text
end getParentFolder

on CheckForFolder(thisFolder)
tell application "Finder"
return (exists folder thisFolder)
end tell
end CheckForFolder

on GetTextItem(ThisString, ThisDelim, ThisItem)
-- ThisString -> String to look in
-- ThisDelim -> Text element that delimit the string
-- ThisItem -> Number of the element to return
copy the text item delimiters to OldDelims
set the text item delimiters to ThisDelim
set arrItem to every text item of ThisString


if class of ThisItem is list then
set FromItem to item 1 of ThisItem
set ToItem to item 2 of ThisItem
set TheReturn to (items FromItem thru ToItem of arrItem) as text
else
if ThisItem ≠ 0 then
set TheReturn to (item ThisItem of arrItem) as text
else
set TheReturn to arrItem -- return every items
end if
end if
set the text item delimiters to OldDelims
return TheReturn
end GetTextItem
« Last Edit: June 11, 2015, 11:09:10 AM by mbornbach »