Monitor Background Printing

Just a thought but is there a way to monitor the process of OSX’s background printing. I want to make a script pause until this process is finished. At the moment I can set a delay but depending on the size of the postscript file being created means changing this delay is nothing but guess work. May be a tell script to pause and do shell script. Is what I want a UNIX CUPS thing I don’t know. The printer in question is the Adobe PDF in printer list if that makes any difference. Many thanks.

On further investigation to this subject in Activity Monitor when viewing with All Processes selected I can see Process ID405 cupsd and it’s processor usage as % this is what I think im after a way to pause until usage = 0.00%

Bump. Here are some old handlers from a quark script OS9 would this still work with X for what I want? I don’t know what they are actualy doing. My PS file vary from 500kb to 500mb per page would this wait until the PS file is complete before passing on to distiller? Any NIX shell scripters know if this can be done? This is kind of what I had in mind.

tell application "Acrobat Distiller 6.0.2"
	activate
	my pause()
	activate
	set destinationPath to POSIX path of "mark-2:users:mark larsen:desktop:"
	set sourcePath to POSIX path of "mark-2:users:mark larsen:desktop:PS Files:Test.eps"
	set adobePDFSettingsPath to POSIX path of "mark-2:users:shared:Adobe PDF 6.0:Settings:Press Quality.joboptions"
	tell application "Acrobat Distiller 6.0.2"
		Distill file
	end tell
end tell

on pause()
	set Wait4CUPS to do shell script "?!@£$%^&"
end pause

opps forgot the old quark stuff

(*This section will distill the PostScript file*)
on DistillFile(filePath)
	tell application "Acrobat Distiller 6.0.2"
		my FileExists(filePath)
		open alias filePath
	end tell
end DistillFile

(*** This will create a delay to give the files time to save ***)
on FileExists(filePath)
	tell application "Finder"
		set go to false
		repeat until go is true
			if exists alias filePath then set go to true
		end repeat
	end tell
end FileExists

If you run this script, you’ll see that (if you have one printer), the second paragraph is the name of the print job that includes the file name and other details. You can parse what you want to know out of that line.

set Pjobs to paragraphs of (do shell script "lpq")

Thanks Adam, that was kind of along the lines that I was looking for with job passing through I can see this information:

tell current application
	do shell script "lpq"
		"AdobePDF is not ready
Rank    Owner   Job     File(s)                         Total Size
1st     marklar 4066    16724 Lee Valley Inspection Lea 12322816 bytes"
end tell

when ended I can see:

tell current application
	do shell script "lpq"
		"AdobePDF is ready
no entries"
end tell

When printing to PS files from within my script these queues are not used. I am a new comer to this scripting may be I need to set up something else in the script first?

You don’t need to tell any application to do a shell script - they are run from the script directly. Without seeing any of the rest of your script, if all you wanted was to pause your script until the printer is free, assuming the examples above are representative, then something like this (where you may have to adjust the paragraph number or text):

-- do stuff to prepare a file for printing
-- send it to the printer (AdobePDF?) from the application

repeat
	if paragraph 1 of (do shell script "lpq") contains "not ready" then
		delay 2 -- this is in seconds
	else
		exit repeat
	end if
end repeat

-- press on with other stuff

Sorry Adam, not paying attention when posting my comments what I posted was the text C&P from the event log window of script editor, Im not telling any current app to do the shell script, I think “tell current application” could mean SE itself. I should have trimmed it down. If the PS files passed through this “lpq” Im sure the script in your last post would work, have yet to test this but many thanks. I will now need to work out why my files printed from the script do not appear in the print utility window just straight to the background spooling.