Pages "Review" Dialog kills this batch convert script

I have this script which does a batch convert of pages files to pdf. It also works great when Pages opens a .doc file EXCEPT when there is an issue (such a missing font) and the “Review” dialog opens. This causes the script to crash. Is there a way to get this script to automatically ignore the Pages “Review” dialog or automatically select “Don’t Review” in the dialog so the script will keep running?

Hi,

first, i would complete this line :

set nuname to (characters 1 thru -(l + 1) of thename as text)

and, use a try-handler:

tell application "Pages"
			launch
			set filname to (destn as string) & nuname & "pdf"
			try
				tell document 1
					open lvar
					save in filname
					close saving no
				end tell
on error
--do something else
			end try
		end tell

if this shouldn’t resolve your script from crashing, try to open your file by using :

do shell script "open -a Pages '" & posix path of lvar &"'"

hope this helps
Jo

Hello

To get rid of the sheet asking you if you want to review the problems report, a bit of GUI scripting is required.


set lvar to ((path to desktop as text) & "2GA-9 Invoice  .pages") as alias
tell application "Finder"
	set thename to name of lvar
	set filex to name extension of lvar
end tell
set l to length of filex

tell application "Pages"
	open lvar
	my checkOpen(thename)
	# Now you may save
end tell

on checkOpen(the_name)
	activate application "Pages"
	tell application "System Events" to tell application process "Pages"
		repeat
			delay 0.5
			if exists window the_name then exit repeat
		end repeat
		tell window the_name
			set noSheet to true
			repeat 10 times
delay 0.2
				if exists sheet 1 then
					set noSheet to false
					exit repeat
				end if
			end repeat
			if noSheet is false then
				tell sheet 1
					--class of UI elements
					--> {static text, button, image, button, static text}
					--name of every button
					--> {"Revoir", "Ne pas consulter"}
					--click button -1
					keystroke (character id 27) # ESCape
				end tell
			end if #  nosheet is false then
		end tell # window the_name
	end tell # System Events & process
end checkOpen


I disabled the instructions grabbing the infos about UI elements belonging to the sheet.
As you may see, you may click the [ Don’t review ] button
but I choose to trigger its shortcut ( ESCape ).

I tested the code with a 8 pages document and with a 600 pages one so I think that it will do the trick for you too.

Yvan KOENIG (VALLAURIS, France) samedi 13 octobre 2012 11:59:23

These are actually both wrong, since both rely on a particular value (“”) for AppleScript’s text item delimiters and neither sets that value first. The correct, TID-independent (and more efficient) version is:

set nuname to text 1 thru -(l + 1) of thename

Thanks all for your time and assistance. I’ll try your suggestions. The problem was actually resolved by installing 3 fonts to simply eliminate the Review dialog from popping up. I almost have my 2000 documents converted (most are only one or two pages in length.)

But I am going to create a version with your suggestions so that both a Review and a non-Reveiw version is available to me to use.

Again, Thanks much! I appreciate your time and expertise.

Hi Nigel

sorry, but i write nothing less what works for me too. I never had a problem using a syntax like:

set nuname to (characters 1 thru -(l + 1) of thename as text)

its a common way for me, to coerce strings. I don’t claim to know all methods about scripting.
However, its because i’m working on OS 10.6 yet ?

Hi Joy.

‘characters . thru . of . as text’ creates a list of characters which is then coerced to text. During the coercion from list to text, the current value of AppleScript’s text item delimiters is inserted between the items. So if the delimiters are set to anything other than their default {“”} or “” ” as they may well be at some point during a script’s execution ” the result can be something other than what you’re expecting:

set AppleScript's text item delimiters to "*"
set thename to "filename.extn"
set l to (count "extn")

set nuname to (characters 1 thru -(l + 1) of thename as text)
--> "f*i*l*e*n*a*m*e*."

If you want to use the coercion method, it’s more robust to set the delimiters explicitly to {“”} or “” before you do.

The ‘text . thru . of .’ syntax, on the other hand, returns the extract directly, without an intermediate list ” which is both more efficient and invulnerable to delimiter errors:

set AppleScript's text item delimiters to "*"
set thename to "filename.extn"
set l to (count "extn")

set nuname to (text 1 thru -(l + 1) of thename)
--> "filename."

jump55’s line .

set nuname to text 1 thru text item -(l + 1) of thename

. is just as good as yours in this respect. It works provided that AppleScript’s text item delimiters are set to their default value, because only then is a ‘text item’ the same as a ‘character’. If you choose to correct what he wrote, it should be with something which isn’t just another manifestation of the same error.

I also did it like Joy.

I realized I saved two coercions, and that it was short to type, by doing it like Nigel.

So, it is both safer and faster by any means.

Hi guys,
i never thought that coercions are so easy.


tell app "Finder" to set item1 to name of item 1 of (get selection)
if "." is in item1 then
set nex to offset of "." in (reverse of characters of item1)
set the_title to text 1 thru -(nex + 1) of item1
end

thanks. It is a little nice useful short type.