Postscripts from QuarkXpress

Hi,

I want to create postscript files from a document opened in QuarkXpress. I’ve searched bbs and found the script that does that. I’ve modified it a little bit to suit my needs. However, I cannot overcome one obstacle which is naming of PS files that are created. The script creates following names for ps files:

  1. If there is less than 10 pages in a document ps files are named: 1_of_9_Document1.ps, 2_of_9_Document1.ps, 3_of_9_Document1.ps etc.

  2. If there is more than 10 but less than 99 pages in a document ps files are named:
    01_of_15_Document1.ps, 02_of_15_Document1.ps, 03_of_15_Document1.ps, …, 010_of_15_Document1.ps, 011_of_15_Document1.ps, etc.

  3. If there is more than 100 but less than 999 pages in a document ps files are named:
    001_of_200_Document1.ps, 002_of_200_Document1.ps, 003_of_200_Document1.ps, …, 0010_of_200_Document1.ps, 0011_of_200_Document1.ps,… 0100_of_200_Document1.ps, 0101_of_200_Document1.ps, 0102_of_200_Document1.ps, etc.

I what the files to be named in this style:

  1. If there is more than 10 but less than 99 pages in a document ps files are named:
    01_of_15_Document1.ps, 02_of_15_Document1.ps, 03_of_15_Document1.ps, …, 10_of_15_Document1.ps, 11_of_15_Document1.ps, etc.

I want to insert zeros before pages from 1 to 9. I don’t want to insert 0 before 10, 11, 12 etc.

  1. If there is more than 100 but less than 999 pages in a document ps files are named:
    001_of_200_Document1.ps, 002_of_200_Document1.ps, 003_of_200_Document1.ps, …, 010_of_200_Document1.ps, 011_of_200_Document1.ps,… 100_of_200_Document1.ps, 101_of_200_Document1.ps, 102_of_200_Document1.ps, etc.

I want to insert two zeros before pages from 1 to 9, one zero for pages 10 to 99. I don’t want to insert 0 before 100, 101, 102 etc.

The script is listed below.


with timeout of 6000 seconds
	try
		set FileName to name of front document of application "QuarkXPress PassportD"
		set thePath to (choose folder with prompt "Choose folder to save PS files:") as text
		tell application "QuarkXPress"
			activate
			tell document 1
				tell print setup
					set data format to binary data
					set resolution to 300
					set page position to left position
				end tell
				set PageCount to count pages
				set PageName to name of page 1
				repeat with i from 1 to PageCount
					set PageName to name of page i
					set i to PageName
					if PageCount < 10 then
						print (page i) PostScript file thePath & i & "_" & "of_" & PageCount & "_" & FileName & ".ps"
					else
						if PageCount >= 10 and PageCount <= 99 then
							print (page i) PostScript file thePath & "0" & i & "_" & "of_" & PageCount & "_" & FileName & ".ps"
						else
							if PageCount >= 100 and PageCount <= 999 then
								print (page i) PostScript file thePath & "00" & i & "_" & "of_" & PageCount & "_" & FileName & ".ps"
							end if
						end if
					end if
				end repeat
				display dialog "Finished!" with icon note
			end tell
		end tell
	on error the error_message number the error_number
		set the error_text to "ERROR: " & the error_number
		display dialog the error_text with icon 0 buttons {"OK"} default button 1
		return the error_text
	end try
end timeout

I’ve searched bbs and the web but didn’t find the solution to my problem.

Thanks in advance for any help!

-Paff

Hi

In place of :

(*if PageCount < 10 then 
                        print (page i) PostScript file thePath & i & "_" & "of_" & PageCount & "_" & FileName & ".ps" 
                    else 
                        if PageCount >= 10 and PageCount <= 99 then 
                            print (page i) PostScript file thePath & "0" & i & "_" & "of_" & PageCount & "_" & FileName & ".ps" 
                        else 
                            if PageCount >= 100 and PageCount <= 999 then 
                                print (page i) PostScript file thePath & "00" & i & "_" & "of_" & PageCount & "_" & FileName & ".ps" 
                            end if 
                        end if 
                    end if *)

try


 set c to (count of characters) of (PageCount as string)
print (page i) PostScript file thePath &( characters -c thru -1 of ("00" & i)) as string & "_" & "of_" & PageCount & "_" & FileName & ".ps" 

I cannot test it. Hope that helps

Hi,

Thanks for the help debloem! I’ve used the code you suggested and it works great both in Quark 6 in 10.3 and Quark 4.11 in 9.2. :smiley:

Could you tell me what exactly this piece of code does:


set c to (count of characters) of (PageCount as string) 
print (page i) PostScript file thePath &( characters -c thru -1 of ("00" & i)) as string & "_" & "of_" & PageCount & "_" & FileName & ".ps" 

-Paff

Hi,

the firt line is to get the count of characters of your pagecount ;
c =1 if pagecount<10
c =2 if pagecount<100
c =3 if pagecount<1000
and the second line : ( characters -c thru -1 of (“00” & i)) as string
is to get the last c characters of the string (“00” & i)
so you get always a value that have the same count of characters than pagecount

You can write ( characters -c thru -1 of (“000” & i)) as string for page count from 1000 to 10000

Sorry for the very bad english :oops:

Debloem