tell application "Adobe InDesign CS5"
activate
if not (exists document 1) then
try
with timeout of 9999 seconds
display dialog "No document open!" buttons "Cancel" default button "Cancel" giving up after 4
end timeout
on error
return
end try
end if
tell active document
if not (exists layer "Third from bottom") then make new layer with properties {name:"Third from bottom", layer color:red}
try
move layer "Third from bottom" to end of last layer
end try
if not (exists layer "Second from bottom") then make new layer with properties {name:"Second from bottom", layer color:red}
try
move layer "Second from bottom" to end of last layer
end try
if not (exists layer "The Bottom") then make new layer with properties {name:"The Bottom", layer color:orange}
try
move layer "The Bottom" to end of last layer
end try
if not (exists layer "Another Layer") then make new layer with properties {name:"Another Layer", layer color:dark green}
if not (exists layer "One More") then make new layer with properties {name:"One More", layer color:dark green}
end tell
end tell
Thanks all!
gary
Model: Mac mini, Intel Core 2 Duo, 2.53 GHz
AppleScript: AppleScript Editor, AppleScript 2.1, Version 2.3
Browser: Safari 534.59.10
Operating System: Mac OS X (10.6)
Might be a bug. I can’t test it but you might have a conflict with keywords. Try putting these things ‘end of last layer’ in vertical bars “|”. i.e “|end of last layer|”. Just a long shot.
what you can do is place beeps in your code to see where you’re at. Mave this section out of the tell block:
tell active document
if not (exists layer "Third from bottom") then make new layer with properties {name:"Third from bottom", layer color:red}
try
move layer "Third from bottom" to end of last layer
end try
if not (exists layer "Second from bottom") then make new layer with properties {name:"Second from bottom", layer color:red}
try
move layer "Second from bottom" to end of last layer
end try
if not (exists layer "The Bottom") then make new layer with properties {name:"The Bottom", layer color:orange}
try
move layer "The Bottom" to end of last layer
end try
if not (exists layer "Another Layer") then make new layer with properties {name:"Another Layer", layer color:dark green}
if not (exists layer "One More") then make new layer with properties {name:"One More", layer color:dark green}
end tell
Place a beep before this. But you need to use another tell block for this section.
tell application "Adobe InDesign CS3"
activate
if not (exists document 1) then
display dialog "No document open!" buttons "Cancel" default button "Cancel" giving up after 4
error number -128 --this prevents any null document from moving on to the next segment
end if
tell document 1
if not (exists layer "The Bottom") then make layer with properties {name:"The Bottom", layer color:orange} at end
if not (exists layer "Second from bottom") then make layer at end with properties {name:"Second from bottom", layer color:red} --whichever object position is fine
end tell
end tell
Didn’t “end tell” work. i deleted two sections to simplify.
tell application "Adobe InDesign CS5"
activate
if not (exists document 1) then
try
with timeout of 9999 seconds
display dialog "No document open!" buttons "Cancel" default button "Cancel" giving up after 4
end timeout
on error
return
end try
end if
tell active document
if not (exists layer "Third from bottom") then make new layer with properties {name:"Third from bottom", layer color:red}
try
move layer "Third from bottom" to end of last layer
end try
end tell
end tell
What I meant is that the first step might be to eliminate the first part. Something like this:
tell application "Adobe InDesign CS5"
activate
if not (exists document 1) then
try
with timeout of 9999 seconds
display dialog "No document open!" buttons "Cancel" default button "Cancel" giving up after 4
end timeout
on error
return
end try
end if
end tell
beep 1 -- added this
-- added this tell
tell application "Adobe InDesign CS5"
tell active document
if not (exists layer "Third from bottom") then make new layer with properties {name:"Third from bottom", layer color:red}
try
move layer "Third from bottom" to end of last layer
end try
end tell
end tell
If you hear a beep, then you know that most likely the error is not coming from the first part.
It takes a little trying, but with beeps and display dialog you can find out a lot with a little thought.
To me that’s the easiest way to debug when you have a fairly big program and you’re not sure where the error is coming from. You go step by step.
Then, you might want to look at the values of your variables if you still can’t figure it out. With the AppleScript in just the Script Editor, you can use display dialog to show you the values of the variables.
The thing is, you need feedback from your script when you’re writing it and later you can get rid of all that feed back.
Edited: and btw, when you get your script to work. you can put it all back together again if you want to. You’ll have learned a lot by then probably.
I’m sorry to hear about your health issue. The code sample you posted mostly worked as-is, although it erred with no document open from its attempt to make layers, so I made that and a few other good-practice changes. A timeout to display a dialog that will destroy itself in a few seconds is unnecessary. The move command and multiple try blocks are also not needed”just indicate where the layer should be made.