Detecting Print Jobs

Scripters,

I am trying to write a script to monitor print jobs, however I can’t seem to find my way out of this infinite loop. My code works great, only the app created from this scriprt won’t quit without being forced. I know what I am doing wrong, but I can’t seem to figure out how to fix it! This script scrapes the last line of the CUPS page log every second, and if there is a change, opens a dialog, and launches FF to a specific URL. TIA for any help.

-- begin variable declaration
-- begin user editable variables
-- message - the message you want the dialog box to display
set message to "Your print job has been added to your queue.  Firefox will now open to a page where you can release this print job.  If this is the first time you are seeing this dialog this session, you will be required to log in using your Novell login."
-- targetURL - the URL you want the user to be durected to upon completion of the print job
set targetURL to "123.123.123.123:8008/AuthJobs"
-- end user editable variables
-- end variable declaration

repeat
	-- set intial values of polling variables
	set old_entry to do shell script "sed '$!d' /var/log/cups/page_log"
	set new_entry to do shell script "sed '$!d' /var/log/cups/page_log"
	-- loop while there are no changes in the cups page log
	repeat while old_entry is equal to new_entry
		delay 1
		set new_entry to do shell script "sed '$!d' /var/log/cups/page_log"
	end repeat
	-- display the dialog and open Firefox with the target URL
	tell application "Finder"
		activate
		display dialog message buttons "OK" with icon 1
	end tell
	tell application "Firefox"
		activate
		OpenURL targetURL
	end tell
end repeat

i’m not exactly sure how to do it but I think you can put in a dialog asking if you want to quit the script and if you say ok then it exits the repeat and I can do that but I’m not sure how to dismiss the dialog if it is not answered

Thanks so much. Works like a charm. Any suggestions on how to convince users to not quit this app? Is there some way to hide it, or take away the option to quit?

Another note for those stumbling upon this thread…

In 10.3 I had to poll the error_log, in 10.4, the page_log (both in /var/log/cups). This may have been isolated to my systems, but try error_log if you aren’t getting proper results.

Thanks a lot. It works beautifully.