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.
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
I noticed your error for paging says “3” does it work for pages 1 and two but not “3”
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
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?
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.
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