I have created a script that creates a desktop folder, takes an open QuarkXPress file and creates eps files into the folder, distills them, then merges all the resulting PDFs into one multipage PDF and discards the eps files. It works without fail.
Now I want to make a droplet for it. The script below, when run as an app and has a file dropped on it, goes as far as the end of the second On-statement and stops. Do I need a third On-statement of some kind to carry the script after “end ifFileExists” to the finish line?
[code]on open some_items
repeat with this_item in some_items
try
tell application “Finder”
set desktopFolder to (path to desktop)
set DestFolder to make new «class cfol» at desktopFolder with properties {name:“New_PDF”}
open «class docf» (this_item)
end tell
end try
end repeat
tell application “QuarkXPress”
activate
try
– This line allows the user to specify a folder into which the EPS files will be saved
set DestFolder to DestFolder as text
tell document 1
set DocName to name as text
set olddelims to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to " :"
try
set DocName to item 1 of (text items 1 thru -2 of DocName)
set AppleScript’s text item delimiters to olddelims
on error errmsg
set AppleScript’s text item delimiters to olddelims
log errmsg
end try
set AppleScript’s text item delimiters to “.”
if text item -1 of DocName = “qxd” then
try
set DocName to text items 1 thru -2 of DocName
set AppleScript’s text item delimiters to olddelims
on error errmsg
set AppleScript’s text item delimiters to olddelims
log errmsg
end try
end if
– This section will cycle through the pages and save each as an EPS
try
set overwrite to null
set curPage to page number of current page
set pageCnt to count of pages
repeat with i from 1 to count of pages
– This section will create the sequential number for the file
set fileNum to “”
repeat until (length of (fileNum as text)) = (length of (pageCnt as text))
if fileNum = “” then
set fileNum to i
else
set fileNum to “0” & fileNum
end if
end repeat
– This line will create the name for the file
set FilePath to DestFolder & DocName & “_” & fileNum & “.eps”
– This following line will invoke a dialog for the first file whose name already exists
– This selection will be applied to subsequent files, so the dialog won’t be display again
set overwrite to my ifFileExists(FilePath, overwrite)
– The following section performs the save, if appropriate
if overwrite is true or overwrite is null or overwrite is “temp” then
save page i in FilePath EPS format PC color EPS data binary EPS scale 100 with transparent page
else if overwrite is “Quit” then
– The user cancelled from the duplicate file notification dialog
– This will end the script
error “User canceled” number -128
end if
end repeat
– The following beep will provide feedback of script completion
beep 2
on error errmsg number errnum
error errmsg number errnum
end try
end tell
on error errmsg number errnum
if errnum is -108 then
beep
display dialog errmsg & return & return & ¬
“Try allocating more memory to " & name & “.” buttons {“OK”} default button 1 with icon stop
return
else if errnum is not -128 then
beep
display dialog errmsg & " [” & errnum & “]” buttons {“OK”} default button 1 with icon stop
end if
return
end try
end tell
end open
–=================================== Handlers =========================================
– Below is the handler (subroutine) that is called from the above script
–===================================================================================
on ifFileExists(FilePath, bOverWrite)
if bOverWrite is null then
– This section will check to see if a file exists, until a matching name has been found
tell application “Finder”
if exists alias FilePath then
tell application “QuarkXPress”
set overwrite to button returned of (display dialog “A file(s) with the same name already exists at this location. Saving will delete the existing file(s).” & return & return & ¬
“Do you want to save anyway?” buttons {“Cancel”, “Don’t Save”, “Save”} default button “Save” with icon caution)
end tell
if overwrite is “Save” then
return true
else if overwrite is “Don’t Save” then
return false
else if overwrite is “Cancel” then
return “Quit”
end if
else
return null
end if
end tell
else if bOverWrite is true then
– This section will keep creating files regardless of whether the names already exist
return true
else if bOverWrite is false or bOverWrite is “temp” then
try
tell application “Finder”
if exists alias FilePath then
– This line will ensure that files whose names already exist are not created,
– if you user previous chose to skip such file
return false
else
– This line will ensure that files whose names don’t already exist will be created,
– if the user previously chose to not overwrite existing files
return “temp”
end if
end tell
on error errmsg number errnum
beep
display dialog errmsg & " [" & errnum & “]” buttons {“Cancel”} default button 1 with icon stop
return
end try
end if
end ifFileExists
tell application “Finder”
set desktopFolder to (path to desktop)
set TheName to every item of «class cfol» “New_PDF” of desktopFolder
repeat with anitem in TheName
tell application “Acrobat Distiller 6.0.2”
activate
open anitem as alias
end tell
end repeat
end tell
delay 15
tell application “Acrobat Distiller 6.0.2”
quit
end tell
tell application “Finder”
set desktopFolder to (path to desktop)
set source_folder to («class cfol» “New_PDF” of desktopFolder) as alias
set AllFiles to (every file of source_folder whose name contains ".pdf")
set theFile to (item 1 of AllFiles)
tell application "Adobe Acrobat Professional"
activate
open theFile as alias
tell application "System Events"
tell process "Acrobat 6.0.2 Professional"
keystroke "b" using command down -- to mark first page
end tell
end tell
repeat with i from 2 to (count of AllFiles)
open item i of AllFiles as alias
tell application "System Events"
tell process "Acrobat 6.0.2 Professional"
keystroke "b" using command down -- to mark first page
end tell
end tell
set combined_page_count to (count page of document 1)
set source_page_count to (count page of document i)
insert pages document 1 after combined_page_count from document i starting with 1 number of pages source_page_count with insert bookmarks
end repeat
close document 1 with saving and linearize
close every document saving no
end tell
set desktopFolder to (path to desktop)
delete (every file of «class cfol» "New_PDF" of desktopFolder whose name does not contain "1.pdf")
set NewFile to item 1 of «class cfol» "New_PDF" of desktopFolder
set FileName to DocName & ".pdf" as text
set name of NewFile to FileName
set deleteMe to every file of «class cfol» "New_PDF" of desktopFolder whose name is not FileName
delete deleteMe
it looks like your trying to merge the PDFs outside of the on open so I made that part into its own sub routine
on open some_items
repeat with this_item in some_items
try
tell application "Finder"
set desktopFolder to (path to desktop)
set DestFolder to make new folder at desktopFolder with properties {name:"New_PDF"}
open document file (this_item)
end tell
end try
end repeat
tell application "QuarkXPress"
activate
try
-- This line allows the user to specify a folder into which the EPS files will be saved
set DestFolder to DestFolder as text
tell document 1
set DocName to name as text
set olddelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to " :"
try
set DocName to item 1 of (text items 1 thru -2 of DocName)
set AppleScript's text item delimiters to olddelims
on error errmsg
set AppleScript's text item delimiters to olddelims
log errmsg
end try
set AppleScript's text item delimiters to "."
if text item -1 of DocName = "qxd" then
try
set DocName to text items 1 thru -2 of DocName
set AppleScript's text item delimiters to olddelims
on error errmsg
set AppleScript's text item delimiters to olddelims
log errmsg
end try
end if
-- This section will cycle through the pages and save each as an EPS
try
set overwrite to null
set curPage to page number of current page
set pageCnt to count of pages
repeat with i from 1 to count of pages
-- This section will create the sequential number for the file
set fileNum to ""
repeat until (length of (fileNum as text)) = (length of (pageCnt as text))
if fileNum = "" then
set fileNum to i
else
set fileNum to "0" & fileNum
end if
end repeat
-- This line will create the name for the file
set FilePath to DestFolder & DocName & "_" & fileNum & ".eps"
-- This following line will invoke a dialog for the first file whose name already exists
-- This selection will be applied to subsequent files, so the dialog won't be display again
set overwrite to my ifFileExists(FilePath, overwrite)
-- The following section performs the save, if appropriate
if overwrite is true or overwrite is null or overwrite is "temp" then
save page i in FilePath EPS format PC color EPS data binary EPS scale 100 with transparent page
else if overwrite is "Quit" then
-- The user cancelled from the duplicate file notification dialog
-- This will end the script
error "User canceled" number -128
end if
end repeat
MergePDFs() -- merge all the resulting pdfs
-- The following beep will provide feedback of script completion
beep 2
on error errmsg number errnum
error errmsg number errnum
end try
end tell
on error errmsg number errnum
if errnum is -108 then
beep
display dialog errmsg & return & return & ¬
"Try allocating more memory to " & name & "." buttons {"OK"} default button 1 with icon stop
return
else if errnum is not -128 then
beep
display dialog errmsg & " [" & errnum & "]" buttons {"OK"} default button 1 with icon stop
end if
return
end try
end tell
end open
--=================================== Handlers =========================================
-- Below is the handler (subroutine) that is called from the above script
--===================================================================================
on ifFileExists(FilePath, bOverWrite)
if bOverWrite is null then
-- This section will check to see if a file exists, until a matching name has been found
tell application "Finder"
if exists alias FilePath then
tell application "QuarkXPress"
set overwrite to button returned of (display dialog "A file(s) with the same name already exists at this location. Saving will delete the existing file(s)." & return & return & ¬
"Do you want to save anyway?" buttons {"Cancel", "Don't Save", "Save"} default button "Save" with icon caution)
end tell
if overwrite is "Save" then
return true
else if overwrite is "Don't Save" then
return false
else if overwrite is "Cancel" then
return "Quit"
end if
else
return null
end if
end tell
else if bOverWrite is true then
-- This section will keep creating files regardless of whether the names already exist
return true
else if bOverWrite is false or bOverWrite is "temp" then
try
tell application "Finder"
if exists alias FilePath then
-- This line will ensure that files whose names already exist are not created,
-- if you user previous chose to skip such file
return false
else
-- This line will ensure that files whose names don't already exist will be created,
-- if the user previously chose to not overwrite existing files
return "temp"
end if
end tell
on error errmsg number errnum
beep
display dialog errmsg & " [" & errnum & "]" buttons {"Cancel"} default button 1 with icon stop
return
end try
end if
end ifFileExists
tell application "Finder"
set desktopFolder to (path to desktop)
set TheName to every item of folder "New_PDF" of desktopFolder
repeat with anitem in TheName
tell application "Acrobat Distiller 7.0"
activate
open anitem as alias
end tell
end repeat
end tell
delay 15
tell application "Acrobat Distiller 7.0"
quit
end tell
on MergePDFs()
tell application "Finder"
set desktopFolder to (path to desktop)
set source_folder to (folder "New_PDF" of desktopFolder) as alias
set AllFiles to (every file of source_folder whose name contains ".pdf")
set theFile to (item 1 of AllFiles)
tell application "Adobe Acrobat 7.0 Standard"
activate
open theFile as alias
tell application "System Events"
tell process "Acrobat 6.0.2 Professional"
keystroke "b" using command down -- to mark first page
end tell
end tell
repeat with i from 2 to (count of AllFiles)
open item i of AllFiles as alias
tell application "System Events"
tell process "Acrobat 6.0.2 Professional"
keystroke "b" using command down -- to mark first page
end tell
end tell
set combined_page_count to (count page of document 1)
set source_page_count to (count page of document i)
insert pages document 1 after combined_page_count from document i starting with 1 number of pages source_page_count with insert bookmarks
end repeat
close document 1 with saving and linearize
close every document saving no
end tell
set desktopFolder to (path to desktop)
delete (every file of folder "New_PDF" of desktopFolder whose name does not contain "1.pdf")
set NewFile to item 1 of folder "New_PDF" of desktopFolder
set FileName to DocName & ".pdf" as text
set name of NewFile to FileName
set deleteMe to every file of folder "New_PDF" of desktopFolder whose name is not FileName
delete deleteMe
end tell
end MergePDFs
Why go to EPS which is a page by page process then join all the single PDFs when you can go print to postscript which is multi page in the first place? Im not sure I understand the logic of this!
The logic lies in saving precious steps.
I work in an ad agency, sometimes I’m up to my butt in alligators. We work in QuarkXPress only because some of our existing files were done in Quark, along with a few art directors who don’t know how to use InDesign. I have a lot of files that are in various stages of completion. I use three different printers, depending on the output I need. I work on a couple dozen clients jobs. Files get revised, and revised, and revised. Each revision gets passed through channels for everyones approval. Then it usually comes back to me about two minutes before I shut down for the day, to make a PDF that gets sent to the client. I’m always working on other things when I get asked to stop and make a PDF. If its a Quark file I have to open the file, change the printer settings to make a PDF, and then remember not to hit save or the next time I make revisions and print them out, I have to change the printer settings again. I’m at home right now so I don’t remember if I also have to change the printer que on my desktop, which also has to be switched back.
With a drag and drop, I could simply drag the Quark file to the icon, then mail the PDF. No switching anything. I don’t revise any Quark files later and print to the color printer, only to find that its been set to print a PDF, meanwhile I’m standing at the color printer waiting for my printout.
This may sound annal, but distractions cause me to lose focus on what I’m currently doing, so the less I have to mess with a distraction, the more focused I can remain on the job at hand.