Revisions to my quark to pdf script....

Hey Stefen,
I am still at it…
if I find a solution, I’ll post it up here.
I may repost over the weekend if I still have no luck in case a quark scripter logs and and sees it…
I’m exhausted and my brain hurts…
thanks again for all your effort.
babs

Hey Stefen, Mark and Pandrake…
Santa figured it out, and got it to work with Quark 8.02-or 8.2
here it is…

property Babs_Folder : “Babs PDF Folder”
global deskPath
global PathToFolder
global PathToFolder2
global tempPictures

on open thefiles
tell application “Finder”
activate
set tempPictures to (every item of (get selection)) – MUST GET BEFORE MAKING FOLDERS
if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
set deskPath to path to desktop as Unicode text
set PathToFolder to POSIX path of (deskPath & Babs_Folder)
set PathToFolder2 to deskPath & Babs_Folder
end tell
my openfiles()
say “Finished”
end open

on openfiles()
try
tell application “Finder”
repeat with LoopFiles in tempPictures
set foundImages to {}
if kind of LoopFiles = “Folder” then
try
set foundImages to files of entire contents of LoopFiles as list
on error
set foundImages to files of entire contents of LoopFiles
end try
else
if kind of LoopFiles is not in {“Volume”, “Disk Image”, “Application”, “Web Internet Location”, “Document”, “Text Clipping”} then
set end of foundImages to LoopFiles
end if
end if
–set WorkingFile to item i of fileList
repeat with WorkingFile in foundImages
if not ((kind of WorkingFile starts with “Quark”) or (kind of WorkingFile starts with “InDesign”)) then
activate
display dialog “This file is not an InDesign or Quark document!” buttons “Skipping” default button “Skipping” with icon 0 giving up after 1
else
–Determine whether to use InDesign subroutines or Quark subroutines
if (kind of WorkingFile starts with “InDesign”) then – Process as InDesign
my createInDesignPDF(WorkingFile, Babs_Folder)
else – Process as Quark
my createQuarkPDF(WorkingFile)
end if
end if
end repeat
end repeat
end tell
on error errmsg
display dialog “OpenFiles.” & return & errmsg giving up after 20
end try
end openfiles

on createInDesignPDF(WorkingFile, savePath)
set x to 0
repeat
if x = 0 then
set newpart to “”
else
set newpart to " " & x
end if
tell application “Finder”
set tempname to my add_extension(WorkingFile, newpart, “pdf”)
if not (exists file tempname in folder Babs_Folder) then exit repeat
end tell
set x to x + 1
end repeat
tell application “Adobe InDesign CS3”
try
try
set user interaction level of script preferences to never interact
end try
open WorkingFile as alias
delay 2
repeat
if exists document 1 then exit repeat
delay 0.2
end repeat
set theProps to properties of PDF export preset “[Press Quality]”
set newProps to {view PDF:true, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
set oldProps to properties of PDF export preferences
set properties of PDF export preferences to newProps
export front document format PDF type to (savePath & tempname) without showing options
set properties of PDF export preferences to oldProps
delay 1
tell documents to close saving no
try
set user interaction level of script preferences to interact with all
end try
on error errmsg
display dialog “CreateIndesignPDF.” & return & errmsg giving up after 20
end try
end tell
end createInDesignPDF

on createQuarkPDF(WorkingFile)
try
set x to 0
repeat
if x = 0 then
set newpart to “”
else
set newpart to " " & x
end if
tell application “Finder”
set tempname to my add_extension(WorkingFile, newpart, “pdf”)
if not (exists file tempname in folder Babs_Folder) then exit repeat
end tell
set x to x + 1
end repeat
tell application “QuarkXPress”
activate
open WorkingFile as alias with Suppress All Warnings
tell application “System Events” to tell process “QuarkXPress”
click menu item “Layout as PDF…” of menu 1 of menu item “Export” of menu 1 of menu bar item “File” of menu bar 1
delay 1
keystroke tempname
delay 1
keystroke “G” using {shift down, command down}
delay 1
keystroke PathToFolder
delay 1
click button “Go” of sheet 1 of window “Export as PDF”
end tell
repeat 2 times
delay 1
activate
tell application “System Events” to tell process “QuarkXPress”
try
if exists button “OK” of window 1 then
click button “OK” of window 1
end if
end try
end tell
end repeat
delay 1
tell application “System Events” to tell process “QuarkXPress”
try
click button “Save” of window “Export as PDF”
end try
end tell
repeat 4 times
delay 1
activate
tell application “System Events” to tell process “QuarkXPress”
try
if exists button “OK” of window 1 then
click button “OK” of window 1
end if
end try
end tell
end repeat
delay 2
close front document saving no
end tell
on error errmsg
display dialog “CreateQuarkPDF.” & return & errmsg giving up after 20
end try
end createQuarkPDF

on add_extension(WorkingFile, new_part, new_extension)
try
set this_info to info for WorkingFile as alias
set this_name to the name of this_info
set this_extension to the name extension of this_info
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
end if
return (the default_name & new_part & “.” & the new_extension)
on error errmsg
display dialog "add extension " & return & errmsg
end try
end add_extension

Sweet!

I’m on MacOSX 10.4 with Quark 7.3, so I expected some difficulties when I tried it. Thus far there’s only a couple of things:

tell application "Finder"
	activate
	set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
	if not (exists folder batch_folder) then make new folder with properties {name:batch_folder}
	set deskPath to (path to desktop) as Unicode text
	--'path to desktop' fails when inside a Finder tell block (whaaa!?!)
	--Finder got an error: Can't make desktop into type constant.

Putting ‘set deskPath to (path to desktop) as Unicode text’ before ‘tell application “Finder”’ solved the problem, tho I’ve not noticed before that ‘path to’ doesn’t work inside a Finder tell in my scripting ventures. Very telling… :wink:

tell application "System Events" to tell process "QuarkXPress"
	click menu item "Layout as PDF..." of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
	delay 1
	keystroke tempname
	delay 1
	keystroke "G" using {shift down, command down}
	delay 1
	keystroke PathToFolder
	delay 1
	click button "Go" of sheet 1 of window "Export as PDF"
	--appears that the "go to folder" item of the Export as PDF window in Quark7
	--is not a sheet (looks like modal dialog)
	--System Events got an error: NSReceiverEvaluationScriptError: 4

Which is where I usually go nuts and give up trying to script Quark’s GUI, as it seems very inconsistent to me. The other parts of it works great, and I never knew that there was a ‘go to’ command for setting the location of a path inside a save/export dialog. Very nice (once I get it figured out how to assuredly click the Go button).

Thanks be to barbarapress and Santa!

path to is a part of Standard Additions, which doesn’t require any application, the Finder has its own terminology


tell application "Finder" to set deskPath to desktop as text

@ barbara and Santa:

I’m wondering why the GUI stuff is really necessary in Quark 8, according the Quark forum the AppleScript command export works

That works, too. I merely pine for the days when Standard Addition terminology (mostly) worked inside any tell block and didn’t need to have a separate “part” of code that I can usually read thru and understand what it’s doing like it’s a script in a play or movie, not a program of handlers, classes, and scope.

export‚v : The Story or the Selection to save into a file using MSWORD filter

I’ve yet to convince upper management there’s value in upgrading and don’t know about Quark 8, but in Quark 7 the export action only applies to text export filters (MSWORD) when exporting stories, the save action that applies to documents, pages, and stories only has the EPS format option for pages, and the print action only has options for postscript. If the export action in Quark 8 has more format options, specifically access to PDF profiles, and works then I’d have an advantage in arguing for an upgrade rather than working around the whole ‘export [what] as [which]’ problem.

path to desktop clashes with the single desktop statement in a Finder tell block, that’s the reason

Indeed it has:
http://forums.quark.com/t/19537.aspx

Whoa. Mahsive cool. It’s not just a command, it’s a whole new Suite!

“sweeeeet!” (pun intended, I don’t really talk that way)

Thanks for the linky. Time for a memo…

Hey Pandrake and Stefen…
I still I needed the GUI because I needed the dialog boxes for missing fonts and images to bypass.
Stefen, I had not tried your scripts with 8 yet… I will back track a bit this week and paly some more with your originals as well, with 8. May have better luck, although I still think I need the GUI to push those buttons for me :wink:

thanks for the tip to the link for quark export and your other comments as always!!!
babs

Ding! Now I see. The ‘suppress all warnings’ bypasses the dialog boxes for missing fonts and images… but only for the open command, and the export process can still throw up dialog boxes with those warnings if there are missing fonts and images. Yes?

That’d be why there’s two loops with ‘if exists button “OK” of window1’ around the ‘click button “Save” of window “Export as PDF”’ - so that if a dialog warning of missing fonts and/or images is encountered it is dismissed and the export is continued. Fonts are not found, images are not relinked, PDF created anyway. Yes?

If that’s the case, doesn’t the export command do the same thing, merely without the dialogs? Is the export command “OK” to dismiss/ignore warnings by default and just create the PDF as commanded even tho there are missing elements?

If you need to stop the process if there are missing fonts/images and correct the problem, then you’d definitely need the GUI since I don’t see anything in Quark’s PDF Suite that would act on that state.

If the export command doesn’t ignore missing fonts and images and does throw warning dialogs, you’d need to use the GUI to dismiss them. Maybe the same kind of ‘if exists button “OK” of window 1’ loop after the export command was issued would work, too.

Here is the latest script from Santa…
I had an issue with missing profiles, so this one bypasses that as well :wink:

property Babs_Folder : “Babs PDF Folder”
global deskPath
global PathToFolder
global PathToFolder2
global tempPictures

]on open thefiles
	tell application "Finder"
		activate
		set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
		if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
		set deskPath to path to desktop as Unicode text
		set PathToFolder to POSIX path of (deskPath & Babs_Folder)
		set PathToFolder2 to deskPath & Babs_Folder
	end tell
	my openfiles()
	say "Finished"
end open

on openfiles()
	try
		tell application "Finder"
			repeat with LoopFiles in tempPictures
				set foundImages to {}
				if kind of LoopFiles = "Folder" then
					try
						set foundImages to files of entire contents of LoopFiles as list
					on error
						set foundImages to files of entire contents of LoopFiles
					end try
				else
					if kind of LoopFiles is not in {"Volume", "Disk Image", "Application", "Web Internet Location", "Document", "Text Clipping"} then
						set end of foundImages to LoopFiles
					end if
				end if
				--set WorkingFile to item i of fileList
				repeat with WorkingFile in foundImages
					if not ((kind of WorkingFile starts with "Quark") or (kind of WorkingFile starts with "InDesign")) then
						activate
						display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 1
					else
						--Determine whether to use InDesign subroutines or Quark subroutines
						if (kind of WorkingFile starts with "InDesign") then -- Process as InDesign
							my createInDesignPDF(WorkingFile, Babs_Folder)
						else -- Process as Quark
							my createQuarkPDF(WorkingFile)
						end if
					end if
				end repeat
			end repeat
		end tell
	on error errmsg
		display dialog "OpenFiles." & return & errmsg giving up after 20
	end try
end openfiles


on createInDesignPDF(WorkingFile, savePath)
	set x to 0
	repeat
		if x = 0 then
			set newpart to ""
		else
			set newpart to " " & x
		end if
		tell application "Finder"
			set tempname to my add_extension(WorkingFile, newpart, "pdf")
			if not (exists file tempname in folder Babs_Folder) then exit repeat
		end tell
		set x to x + 1
	end repeat
	tell application "Adobe InDesign CS3"
		try
			try
				set user interaction level of script preferences to never interact
			end try
			open WorkingFile as alias
			delay 2
			repeat
				if exists document 1 then exit repeat
				delay 0.2
			end repeat
			set theProps to properties of PDF export preset "[Press Quality]"
			set newProps to {view PDF:true, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
			set oldProps to properties of PDF export preferences
			set properties of PDF export preferences to newProps
			export front document format PDF type to (savePath & tempname) without showing options
			set properties of PDF export preferences to oldProps
			delay 1
			tell documents to close saving no
			try
				set user interaction level of script preferences to interact with all
			end try
		on error errmsg
			display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
		end try
	end tell
end createInDesignPDF

on createQuarkPDF(WorkingFile)
	try
		set x to 0
		repeat
			if x = 0 then
				set newpart to ""
			else
				set newpart to " " & x
			end if
			tell application "Finder"
				set tempname to my add_extension(WorkingFile, newpart, "pdf")
				if not (exists file tempname in folder Babs_Folder) then exit repeat
			end tell
			set x to x + 1
		end repeat
		tell application "QuarkXPress"
			activate
			open WorkingFile as alias with «class SPRS»
			tell application "System Events" to tell process "QuarkXPress"
				click menu item "Layout as PDF..." of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
				delay 1
				keystroke tempname
				delay 1
				keystroke "G" using {shift down, command down}
				delay 1
				keystroke PathToFolder
				delay 1
				click button "Go" of sheet 1 of window "Export as PDF"
			end tell
			repeat 2 times
				delay 1
				activate
				tell application "System Events" to tell process "QuarkXPress"
					try
						if exists button "OK" of window 1 then
							click button "OK" of window 1
						end if
					end try
				end tell
			end repeat
			delay 1
			tell application "System Events" to tell process "QuarkXPress"
				try
					click button "Save" of window "Export as PDF"
				end try
			end tell
			repeat 4 times
				delay 1
				activate
				tell application "System Events" to tell process "QuarkXPress"
					try
						if exists button "OK" of window 1 then
							click button "OK" of window 1
						end if
					end try
					try
						if exists button "List Profiles" of window 1 then
							click button "Continue" of window 1
						end if
					end try
				end tell
			end repeat
			delay 2
			close front document saving no
		end tell
	on error errmsg
		display dialog "CreateQuarkPDF." & return & errmsg giving up after 20
	end try
end createQuarkPDF

on add_extension(WorkingFile, new_part, new_extension)
	try
		set this_info to info for WorkingFile as alias
		set this_name to the name of this_info
		set this_extension to the name extension of this_info
		if this_extension is missing value then
			set the default_name to this_name
		else
			set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
		end if
		return (the default_name & new_part & "." & the new_extension)
	on error errmsg
		display dialog "add extension " & return & errmsg
	end try
end add_extension
[/applescript