InDesign script works in Tiger, not in Leopard

Hello,
Why would an applescript work in Tiger, but fail in Leopard. Below is the script. The comments show where the script fails.

Any ideas?


tell application "Adobe InDesign CS3"
	set user interaction level of script preferences to never interact
end tell

(*
The above works in Tiger, fails in Leopard.
*)


set OutputFolder to (choose folder with prompt "Please select the Watched Folder")
set OutputFolderPath to OutputFolder as string

set Mag_Issue to text returned of (display dialog "What is the CMP code? This will be the first part of the postcript file's name." default answer "XYZ-004" buttons {"OK"} default button 1)

tell application "Adobe InDesign CS3"
	set presetList to name of printer presets
	set myPreset to (choose from list presetList) as string
	
	set myFile to (choose file)
	open myFile
	set myPages to every page of active document
	repeat with i from 1 to count of myPages
		set myPage to item i of myPages
		set myPageNumb to name of myPage
		if length of myPageNumb = 1 then
			set finNumb to "_00" & myPageNumb
		else if length of myPageNumb = 2 then
			set finNumb to "_0" & myPageNumb
		else
			set finNumb to "_" & myPageNumb
		end if
		
		set filePath to OutputFolderPath & Mag_Issue & finNumb & ".ps"
		
		with timeout of 1200 seconds
			tell active document
				tell print preferences
					set active printer preset to myPreset
					set page range to myPageNumb --this fails in Leopard, error message says it was expecting a string, but received "3" which is a string
					
					set printer to postscript file
					set print file to filePath
				end tell
				print without print dialog
			end tell
		end timeout
	end repeat
	
	close active document saving no
end tell


tell application "Adobe InDesign CS3"
	set user interaction level of script preferences to interact with all
end tell

I can only speculate, as I do not have Leopard or InDesign.

Leopard changed AppleScript’s strings to always be the equivalent of Tiger’s Unicode text. Maybe InDesign does not handle Unicode text-type strings for page rage?

In another thread Jacques reported that Adobe Acrobat’s do script can not handle JavaScript code passed in the Unicode text format. Jacques provided a handler that could convert a Leopard string into an old-style TEXT string. You might try adopting that handler and using set page range to my ConvertUnicodeToDataText(myPageNumb).

Since your string is just a number, another approach that might work is set page range to (myPageNumb as number). Again, the aim is to avoid passing Leopard’s internal Unicode text-type string object. Hopefully InDesign will know how to use the number directly or will be able to coerce it to the text format it wants.

Sorry for the noise if none of this works.

chrys
This works for me


		set UI to user interaction level of script preference 1 -- save the current UI level
		set user interaction level of script preference 1 to never interact -- set my own UI level

				--- do stuff

		set user interaction level of script preference 1 to UI -- set the UI level back to the way I found it

I’m not really sure whats going on with your page range I copied and pasted your code in and it worked fine for me I have some question though that may lead us to an answer

  1. I noticed your error for paging says “3” does it work for pages 1 and two but not “3”

  2. are you on an intel machine ?

mm

Thanks for both replies.

It may be a Unicode text problem, because I asked for myPageNumb’s class and got Unicode Text. BUT, I coerced myPageNumb to a string, got the class as string, but the script still failed (with the same error). I also tried coercing it to an integer, but InDesign does not accept anything but the word “all” or a string.

When I wrote this on my Tiger Mac Pro machine, it initially worked like a charm. I was writing it for my coworker who works on Leopard (which is intel based) and when I compiled it on his machine, that’s when I started getting the error messages.

Now, I copied the applet back to my Tiger machine and am getting the error. Not only that but the script fails due to modal dialog boxes which I thought setting user interaction level of script preferences to never interact was supposed to prevent.

I won’t have a chance to try set UI to user interaction level of script preference 1 til later, but I will let you know how that works out.

myPageNumb could be any page number (“1” or “2” or “3” or n…)

In the meantime we decided to use the export as pdf function in InDesign on my machine, and it did the job (meaning we got the issue out on deadline!):


global myPreset

tell application "Adobe InDesign CS3"
	set user interaction level of script preferences to never interact
end tell

set OutputFolder to (choose folder with prompt "Please select the watched folder")
set OutputFolderPath to OutputFolder as string

set Mag_Issue to text returned of (display dialog "What is the IB CMP code? This will be the first part of the postcript file's name." default answer "ICB-004" buttons {"OK"} default button 1)

tell application "Adobe InDesign CS3"
	set presetList to name of PDF export presets
	set theChoice to choose from list presetList without multiple selections allowed
	if theChoice is not false then
		set myPreset to item 1 of theChoice
	end if
	
	
	set myFile to (choose file)
	open myFile
	set myDoc to active document
	set myPages to every page of active document
	repeat with i from 1 to count of myPages
		set myPage to item i of myPages
		set myPageNumb to name of myPage
		if length of myPageNumb = 1 then
			set finNumb to "_00" & myPageNumb
		else if length of myPageNumb = 2 then
			set finNumb to "_0" & myPageNumb
		else
			set finNumb to "_" & myPageNumb
		end if
		
		set filePath to OutputFolderPath & ICB_Issue & finNumb & ".pdf"
		
		with timeout of 1200 seconds
			
			tell PDF export preferences
				set exProp to {view PDF:true, page range:myPageNumb}
			end tell
			set properties of PDF export preferences to exProp
			
			set aPreset to myPreset
			
			tell application "Adobe InDesign CS3"
				export myDoc format PDF type to filePath using PDF export preset aPreset
				
			end tell
		end timeout
	end repeat
	close active document saving no
	
end tell

tell application "Adobe InDesign CS3"
	set user interaction level of script preferences to interact with all
end tell

I haven’t tried this yet on Leopard.

This may sound silly but have you tried re-compiling the script on the original machine and seeing if that fixes the problem ?

mm

Yes. Sorry, still didn’t work.

Thanks.

paeon

Was just able to use the suggestion from mcgrailm and set UI to user interaction level of script preference 1 and that stopped the modal dialog alerts. But now I have another problem. The script to export to PDF above works on Tiger, but not on Leopard. On Tiger the class of myPageNumb is string; on Leopard the class is text. What happens is that for each repeat loop, a pdf of all pages is exported, even tho the event log is showing that myPageRange is only one page number per iteration.

So I tried implementing Chrys’ suggestion: the handler ConvertUnicodetoDataText and that did not work. I tried implementing it on the first script above (printing to postscript) and that did not work. I also coerced the text to a number and that didn’t work either.

I’m thinking that InDesign CS3 won’t accept class text and Leopard’s AS does not have a class string.

Is it possible to install an older version of AS onto Leopard and would that make a difference? Is this a ploy to make me buy CS4?

Thank you all.

Paeon

I’m running CS3 on 10.5 and it works for me. I did have to change one line:

set filePath to OutputFolderPath & ICB_Issue & finNumb & ".pdf"

to

set filePath to OutputFolderPath & Mag_Issue & finNumb & ".pdf"

once I did that it saved out each page of the ID doc as a separate PDF then opened them in Actobat. Might be time for trashing and rebuilding preferences.

I don’t ever think downgrading your AS is a wise idea but I’m sure you could find people to argue that with me.

I don’t think this is a CSx issue so much as it may be an AS OSX issue with how strings or text /unicode text is handled

I think it would be wise to check the version of AS you are running being as two of us have copied your code and had success

it would also be good to make sure for whatever wacky reason the script is not running through rosetta

hth
Mike

Thanks for the confirmation and the insight. I will try to find another imac with Leopard to run these scripts and if they run okay, obviously it is one particular machine in question.

Thanks all for your input. Now I just need to learn how to make the scripts run faster.

I’m not sure if it is any faster, the part that takes the longest is the exporting which the script cannot speed up, but here is a version that is cleaned up and reworked a little:

set OutputFolderPath to (choose folder with prompt "Please select the watched folder") as string

set Mag_Issue to text returned of (display dialog "What is the IB CMP code? This will be the first part of the postcript file's name." default answer "ICB-004" buttons {"OK"} default button 1)

set myFile to (choose file)

tell application "Adobe InDesign CS3"
	activate
	set user interaction level of script preferences to never interact
	set presetList to name of PDF export presets
	set theChoice to choose from list presetList without multiple selections allowed
	if theChoice is not false then
		set myPreset to item 1 of theChoice
		set myDoc to open myFile
		set myPages to name of every page of myDoc
		repeat with myPage in myPages
			set finNumb to "_" & characters -3 through -1 of ("000" & myPage)
			set filePath to OutputFolderPath & Mag_Issue & finNumb & ".pdf"
			with timeout of 1200 seconds
				set properties of PDF export preferences to {view PDF:true, page range:myPage}
				export myDoc format PDF type to filePath using PDF export preset myPreset
			end timeout
		end repeat
		close active document saving no
	end if
	set user interaction level of script preferences to interact with all
end tell

Thanks, Jerome. I’ll also redo the dialog so that it makes sense:D