Author Topic: My PDF "One Click" script  (Read 1585 times)

0 Members and 1 Guest are viewing this topic.

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
My PDF "One Click" script
« on: April 09, 2010, 09:58:14 AM »
Finished my "one-click" PDF script. Uses QX's Export (not Distiller).

The big deal for me is file naming, so a lot of the code is devoted to adding a suffix(es).
Also, I like the PDF being made in the same folder as the QXP file.

Any comments/suggestions?


set theList to {"MDA.", "Fins.", "shell", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "", "after", "SPEC", "", "a", "b", ".1", ".2", ".3", ".4", ".5", ".CL", ".BL", ".Cumulative", ".Current"}

tell document 1 of application "QuarkXPress"
     set horizontal measure to inches
     set fullpathofile to file path as text
     set quarkfilename to name as string
     set quarkfilename to (text 1 thru -5) of quarkfilename as string
     set thePageWidth to page width as real
     --     return thePageWidth
     if thePageWidth is less than 8.25 then
          set pdfsettings to "PDF w Crops" as text
     else
          set pdfsettings to "PDF no Crops" as text
     end if
     set horizontal measure to picas
end tell
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pathoffolder to (((text items 1 thru -2 of (fullpathofile as text)) as text) & ":") as text
set AppleScript's text item delimiters to tid

--add suffix of filename
set suffix to (choose from list theList with prompt "suffix?" with multiple selections allowed)

if suffix is false then
     return
end if

--display dialog C
set PDF_path to (pathoffolder & quarkfilename & "." & suffix & ".pdf") as text
tell document 1 of application "QuarkXPress"
     --     export in PDF_path PDF output style "PDF no Crops"
     export in PDF_path PDF output style pdfsettings
end tell
[/quote]

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Re: My PDF "One Click" script
« Reply #1 on: April 20, 2010, 03:46:28 PM »
hey AF.  how are you doing? 
I did a similar script a little while ago (with help from P-S forum of course), which i'm currently looking at adding a few extra If statements and bells and whistles.

your script looks good. one suggestion... i added an auto deletion if the file already exists, effectively over-writing the file.
Code: [Select]
		try
if exists (file pdf_name) then
delete (file pdfname)
end if
end try
just an idea, it may not be a feature you want. :-)


Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: My PDF "One Click" script
« Reply #2 on: April 20, 2010, 05:57:57 PM »
Hey 46,

Absolutely appreciate it.

Post your script, so I (we) can take a look.


Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Re: My PDF "One Click" script
« Reply #3 on: April 25, 2010, 10:31:08 PM »
hey a/f.  i'll post what i have.  this is one of the first scripts i wrote when i started -- when i joined this forum. when i look at many of the scripts posted on this site, i love how they are all so tight... and then i look at mine ... each little step as its own command, where many could be consolidated, it stumbles from one task to the next.  its why i am looking to overhaul them and start from scratch.

one of the things i wanted to do was break out everything into individual bite-size scripts using the "run script" command, but thats just driving me crazy trying to keep track of which variables i need to carry over and back and how to logically break up scripts into pieces. theres a lot of cross-over in the scripts ive written so it would be logical to break into "open file" "update slug" "export as pdf" etc. but how to make one cookie cutter "update slug" that slots into each of the various scripts.  arrrgh.

below is the script i wrote. i'm a little embarrassed cos its not streamlined code, but it does work.. er most of the time. the main idea is that i jump to the mac, punch in the job number, jump back to the PC, continue working on whatever else i am on, and grab the file, email and done! (as print final requests need only be printed and sent).

these scripts feed off a very specific template, so they are predictable documents. the tricky thing is that i dont know what the file name will be so i use tell finder "open every qxd document in the job folder" but it would be better if i found out the name, and then said open this_file, and if there is more than one (which is rare but happens), ask user to choose, or print pdfs of both, adding a suffix. theres other stuff in there, where you can see that its a modified script of a slightly different iteration.

hahah. see i am just as verbose in my communications as i am in my scripting... :-)  any suggestions or "pointers in the right direction" would be welcome.
m./
p.s. i always enjoy your posts. very thought provoking for the most part (tho often topics above my knowledge).

Code: [Select]
tell application "Finder"
activate
display dialog "Enter Job Number" & return & "e.g. 000123: " & return & return & "Your PRESS FINAL will be in the job folder :-0" default answer "" buttons {"Cancel", "OK"} default button {"OK"} with title ("Start_2_Final: Create a Press Final.")
set jobanswer to result as list
end tell

-- ----------------------------------------------------------
-- fix the jobnumber// allow for user error
-- i.e. putting in "k" or "v" at start
-- ----------------------------------------------------------
tell application "Finder"
set AppleScript's text item delimiters to ""
set jobnum to (item 1 of jobanswer) as string
if jobnum is "" then
display dialog ("You did not enter a job number. Type in and try again") default answer "" buttons {"Cancel", "Try Again"} default button {"Try Again"}
set jobanswerII to result as list
set jobnum to (item 1 of jobanswerII) as string
if jobnum is "" then
display dialog ("you still havent entered a job number. sigh. please come back when want to do some work.") default button {"ok"}
return
end if
end if
if jobnum contains "v" then
set jobnum to (items 2 thru 7 of jobnum) as string
else if jobnum contains "k" then
set jobnum to (items 2 thru 7 of jobnum) as string
end if
set jobnum to (items 1 thru 6 of jobnum) as string
set jobnumfin to ("V" & jobnum) as string
end tell
set aliasyn to (item 2 of jobanswer) as string
if aliasyn is "Cancel" then
return
-- ----------------------------------------------------------
-- if answer is NOT cancel then job is opened and alias is created
-- ----------------------------------------------------------
else
tell application "Finder"
activate
make new alias file at desktop to folder jobnumfin of disk "CLIENTS" of application "Finder"
open result
open (every document file of front Finder window whose kind is "QuarkXPress Project File" or name extension is in {"qxd", "qxp"} and name starts with "k")
delete (every alias file of the desktop whose name contains jobnumfin)
end tell
end if
-- -------------------------------------------------------------------
-- check to see if there is an open file
-- --------------------------------------------------------------------
tell application "QuarkXPress"
activate
if not (exists document 1) then
display dialog ("Unable to open file.") with title ("oooops") buttons {"OK"} default button 1
-- --------------------------------------------------------------------
-- [TO COME option to "open job" sub routine]??
-- --------------------------------------------------------------------
return
end if
end tell
-- ---------------------------------------------------------------------------------------------
-- ---------------------------------------------------------------------------------------------
-- actions to set variables:
-- ---------------------------------------------------------------------------------------------
-- ---------------------------------------------------------------------------------------------
-- get the k job number and name
-- --------------------------------------------------------------------
tell application "QuarkXPress"
activate
tell layout space 1 of project 1
set kname1 to name as string
set ATID to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set s to the (count of text items in kname1) as string
-- --------------------------------------------------------------------
-- split out the name, description and proof no.
-- --------------------------------------------------------------------
set kcn to (text items 1 thru (s - 2) of kname1)
get kcn
set kcn to result as string
set proofno to (text items -2 thru -1 of kname1) as string
-- --------------------------------------------------------------------
-- get job description from layout name (var: jobd/jobdesc)
-- --------------------------------------------------------------------
set proofnono to (first text item of proofno)
set the nowdate to do shell script "date '+%m/%d/%y — %H:%M'"
end tell
end tell

-- --------------------------------------------------------------------
-- get job number -- to be used in 'save as' path.
----------------------------------------------------------------------
-- action to Create PDF
----------------------------------------------------------------------
tell application "Finder"
-- --------------------------------------------------------------------
-- first check if there is already a draft by this name
-- delete if yes
-- --------------------------------------------------------------------
set pdfname to (kcn & " " & proofnono & " Final.pdf") as string
if exists (file pdfname of folder jobnumfin of disk "CLIENTS" of application "Finder") then
delete (file pdfname of folder jobnumfin of disk "CLIENTS" of application "Finder")
end if
end tell

tell application "QuarkXPress"
activate
-- --------------------------------------------------------------------
-- check if non-printing exists, suppress print if yes,
-- --------------------------------------------------------------------
if (exists layer "Non-Printing") of layout space 1 of project 1 then
tell layer "Non-Printing" of layout space 1 of project 1
set properties to {suppress print:true, visible:false}
end tell
else
display dialog ("There is no “Non-Printing“ layer") & return & return & ("This means you may still have the non-printing boxes as part of this proof")
end if
set pdfpath to (":Volumes:CLIENTS:" & jobnumfin & ":" & pdfname)
export layout space 1 of project 1 in pdfpath as "PDF" PDF output style "NCR_letter_(FINAL)"
end tell
set AppleScript's text item delimiters to ATID

tell application "QuarkXPress"
close document 1 saving no
end tell