Quark - folder action script

I have a folder action script which handles Quark files.
It works well and takes around 45 seconds per document.


on adding folder items to this_folder after receiving added_items
    
    repeat with this_item in added_items
        tell application "QuarkXPress"
            open this_item
            my Documentpreparation()
            my HTMLcodeBodyText()
            my CIPcode()
            my ImageFileNames()
            my TrimLogoBox()
            my TrimPicBox()
            my EditCaptions()
            save document 1
            close document 1
        end tell
    end repeat
    
    beep 2
    
    --- user reminder
    display dialog "Processing is complete." buttons {"Finish"} default button 1
    
end adding folder items to

However, Quark inevitably quits before all the documents are completed.
This morning it got through 15 (out of 100); it has done as many 60 (out of 150).

Does anyone have any idea where the fault lies? The Applescript, Quark, my computer …

All advice greatly received.

Thanks

Mark
[Quark 6.5
OS X 10.4.8]

You may want to try purging the prefs file every so often. The prefs have a nasty habit of corrupting.

let us know if that helps :slight_smile:

mm

Ummm…so it really doesn’t work well.

With Xpress Scripts there are tons of things to look out for. When you say it quits, how does it quit?

Can’t tell what any of your subroutines do so:

Applescript in Xpress can:

choke on certain images
choke on certain text characters
bail out if an object isn’t available
error out due to time
hang up on a dialog box
get ahead of itself

…and probably much more.

-N

The quit message is from OS X - ‘The application QuarkXPress quit unexpectedly’.
It’s not an Applescript or Quark error message.

Purged the prefs file - made no difference.

The sub-routines are fairly inoffensive “ gather file names in order them; check text. And it doesn’t seem to be the attributes of an individual document (i.e. a certain image or text character, or a missing object) as I can run the script individually (and successfully) on all the documents. I can also rerun the Folder Action script (after restarting Quark) and it handles a document it quit on previously with no problems and vice versa.

I don’t think it’s an error due to time out as it doesn’t take longer than 60 seconds to process a single document, and the only dialog box is the one at the end that tells you its finished.

So, that leaves me with ‘getting ahead of itself’ or something else.
Hmmmm, both seem suitably unfathomable.

If anyone has any experience with a similar problem please let me know.
Otherwise, thanks for the input.

Cheers

Mark

how about if you have it quit out of quark after it processes say five docs does that help ?

mm

Mark,

Excellent input.

The next step I’d try is to reconfigure the script to handle a folder full of files and not run it as a Folder Action. That way you can isolate a bit more to see if that’s the problem.

You can also try building in delays at certain points in your script where files get written, etc to see if that helps.

I’ve also had one where to make it “bulletproof” I had to build a document and save it, quit Xpress, open the document back up and do some more processing. If all else fails…

-N

An update …

I changed the script to handle a folder full of files. This was a little more stable but did still quit. Various Applescript errors were cited - can’t get this variable or that variable etc. I did tighten up some of the code but I don’t think that this is really the problem as I could rerun the script and it would work fine on any one particular document.

I then incorporated mcgrailm’s suggestion of quitting / restarting Quark. I set the document count to eight. I ran it last night and it did 81 docs (a new record) before quitting (leaving 190 still to go).

This is the code as it stands.


tell application "Finder"
	
	--- select folder with files to process
	set the source_folder to (choose folder)
	set file_list to every item of the source_folder
	
	--- count the number of docs Quark has processed
	set Quark_count to 0
	
	--- processing loop with quit from Quark after 8 docs
	repeat with i from 1 to the count of file_list
		tell application "QuarkXPress"
			activate
			open item i of file_list
			my Documentpreparation()
			my HTMLcodeBodyText()
			my CIPcode()
			my ImageFileNames()
			my TrimLogoBox()
			my TrimPicBox()
			my EditCaptions()
			save document 1
			close document 1
			set Quark_count to Quark_count + 1
			if Quark_count is greater than 8 then
				quit "QuarkXPress"
				set Quark_count to 0
			end if
		end tell
	end repeat
	
	beep 2
	
	--- user reminder
	display dialog "Processing is complete." buttons {"Finish"} default button 1
	
end tell

My next steps will be to try building in delays and, if necessary, drop the document count further.

Thanks for the suggestions - all have been gratefully received.

Mark

Have you tried using any of the open file options like “use doc prefs yes remap fonts no do auto picture import yes without reflow” the most common thing Quark will crash out with is font curruption and building image previews.

Mark,

You may want to try purging the prefs when you quit quark as well… just a question why do you if quark quits won’t the script just relaunch quark or are you get the great “connection invalid” dialog and if thats the case there has got to be a way to dismiss the dialog.

mm

OK, I will try purging the prefs on every Quark quit.

Sorry, but don’t really understand your second comment on the Quark quit statement; I don’t have any ‘connection invalid’ problems - what alternatives are there?

Will also look at Mark67’s opening file options.

Thanks

Mark

Mark,

sorry typos … anyhow what I was trying to ask is if quark quits why don’t you have the script just relaunch it ?

MM

Hi Guys

Sorry to stick my nose in here.

But recently had a quark unexpectedly quitting error.
it turned out to be a permissions thing in the user it was in.
Not sure if this is your problem, but worth looking into or tinkering with.
good luck…

pidge1,

what exactly was the permissions problem ?

mm

Quark by default does not install into the applications folder with the correct permissions to allow for usage with users other than admin. You have to reset this manually with get info on the Quark app folder. Another real pain in the rear is that the menubar scripts access drops out quite regularly. This drives me nuts and requires a Quark re-launch to get it back. Been a known issue for ages but never addressed.

Like Mark67 says they were just wrong i had heard somewhere as well after i got it sorted that quarkxpress does this by default (shame on you Quarkxpress!).
Can’t remember what i did just changed them around and it cured it.
Can’t say this will cause the script to work okay just thought it might be relevant.

:o ore things to make life miserable …

Update …

I was getting invalid connection errors last week so started with a belt and braces approach of using more try / end try statements, using Quark to process only four documents and then quitting / restarting itself, and building in time delays to slow the whole process down and stop the script getting ahead of itself.


tell application "Finder"
	
	--- select folder with files to process
	set the source_folder to (choose folder)
	set file_list to every item of the source_folder
	
	--- count the number of docs Quark has processed
	set Quark_count to 1
	
	--- processing loop with quit from Quark after 4 docs
	repeat with i from 1 to the count of file_list
		tell application "QuarkXPress"
			activate
			delay 10 
			open item i of file_list
			my Documentpreparation()
			my HTMLcodeBodyText()
			my CIPcode()
			my ImageFileNames()
			my TrimLogoBox()
			my TrimPicBox()
			my EditCaptions()
			try
				save document 1
			end try
			try
				close document 1
			end try
			set Quark_count to Quark_count + 1
			if Quark_count is greater than 4 then
				quit "QuarkXPress"
				delay 10 
				set Quark_count to 1
			end if
		end tell
	end repeat
	
	beep 2
	
	--- user reminder
	display dialog "Processing is complete." buttons {"Finish"} default button 1
	
end tell

Worked without a hitch on my computer. Wouldn’t work on a colleague’s computer who accesses Quark on a central server (Quark wouldn’t reactivate).

I thought that the time delay was the most important element so, in the interests of efficiency, stripped out the quit / restart code (and dropped the delay times to 7 seconds).


tell application "Finder"
	
	--- select folder with files to process
	set the source_folder to (choose folder)
	set file_list to every item of the source_folder
	
	--- processing loop with delay to ensure script does not get ahead of itself
	repeat with i from 1 to the count of file_list
		tell application "QuarkXPress"
			activate
			delay 7
			open item i of file_list
			my Documentpreparation()
			my HTMLcodeBodyText()
			my CIPcode()
			my ImageFileNames()
			my TrimLogoBox()
			my TrimPicBox()
			my EditCaptions()
			try
				save document 1
			end try
			delay 7
			try
				close document 1
			end try
		end tell
	end repeat
	
	beep 2
	
	--- user reminder
	display dialog "Processing is complete." buttons {"Finish"} default button 1
	
end tell

This works on my computer, as well as on theirs. I am taking this as success and moving on. If I had the time I would try reducing the delay times, but I don’t so I’ll stick with what I’ve got.

Thanks for all input.

Mark

I have several Quark scripts where delays are a must for some reason. A loop to fire off pages to postscript files will always fall over without this. Good to see its sorted. nedloh99 did suggest this earlier on.

Absolutely. Using delays wasn’t my idea - it just took me a while to work my way through everyone’s input.

Mark