Apple Event Madness... This is a tough one

I have been scripting an automated freehand print for months now here is a list of problems:

The dictionary command Print just brings up the print dialog and stops. Macromedia broke this nice little script functionality

so I decided to write a complex GUI script that sets the settings I need and clicks print for me through System Events. This works great except there is one problem. Depending on the file size, the spool process can take some time. If it takes too long, the script moves on and closes the document while it is still spooling and causes freehand to crash unconditionally, every time.

I can put a delay in between the GUI print command and the Tell application “Freehand MX” close without saving command but it is not so nice and neat. Who wants to wait 25 seconds just to keep from erroring out on large docuemnts when most documents spool in 1 second.

Now here is the tough question:
I have captured the apple event that is called during the process of printing
{ 1 } ‘aevt’: ppxy/PCpr (****){
return id: 45547521 (0x2b70001)
transaction id: 0 (0x0)
interaction level: 112 (0x70)
reply required: 0 (0x0)
remote: 0 (0x0)
{ 1 } ‘aprl’: 62 bytes {
000: 6669 6c65 3a2f 2f6c 6f63 616c 686f 7374 file://localhost
001: 2f55 7365 7273 2f63 7061 756c 696e 2f4c /Users/cpaulin/L
002: 6962 7261 7279 2f50 7269 6e74 6572 732f ibrary/Printers/
003: 5044 4677 7269 7465 722e 6170 702f


optional attributes:
< empty record >
event data:
{ 1 } ‘aevt’: - 0 items {

Can I get the script to wait for completion of this event before moving on to the next part of the script?

Here is a short version of the script without setting all the print preferences.

tell application “FreeHand MX”
tell application “Finder” to set the source_folder to (folder “Freehand” of folder “ENCHILADA_FOLDERS”) as alias
set source_folder to source_folder as alias
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set documentName to this_item as string
set this_item to (source_folder & this_item) as alias
open this_item without Dialogs
tell application “System Events”
tell application process “FreeHand MX”
click menu item “Print…” of menu “File” of menu bar item “File” of menu bar 1
click button “Print” of UI element 4 of window “Print”
end tell
end tell
tell application “Freehand MX”
close without saving
end tell
end repeat
end tell

any idea how to make it wait until «event ppxyPCpr» has completed before moving on to close without saving?


I don’t have Freehand so don’t know about its scriptability. Maybe you can wait for the Print Center to quit. Something like this:

– after your print thingy
– wait for Print Center to begin
tell application “System Events”
set i to 0
set i to i + 1
if (exists process “Print Center”) or (i > 10000) then exit repeat
– would Print Center not run? I don’t know. Just in case, use counter.
– may have problems with stopped jobs
– maybe script Print Center
end repeat
– wait for Print Center to quit
repeat while (exists process “Print Center”)
do shell script “sleep 1”
end repeat
end tell
beep 3 – printing done

Along the way, I was thinking that you may have problems with stopped jobs as I frequently do. You might check on this. I don’t like to waste ink.

Edit: I should have wrote that I didn’t test this out yet. It’s just an idea.