-
1. Re: InDesign library: How is this possible?
John Hawkinson Jul 1, 2013 7:30 PM (in response to RobertKyle)Have you tried instead
if (app.libraries && app.libraries.itemByName("Bob.indl") && app.libraries.itemByName("Bob.indl").isValid)
?
The first one is probably unnecessary, and arguably you should cache the result of the itemByName in a variable, but you get the idea...
(Also, it's generally recommended that you not test if (var==true); just use if (var).)
-
2. Re: InDesign library: How is this possible?
suripappu Jul 1, 2013 9:52 PM (in response to RobertKyle)hi, by using apple script
tell application "Adobe InDesign CS5" set lib to libraries
if count of lib > 0
--already open
else
--not open
end if
end tell
-
3. Re: InDesign library: How is this possible?
RobertKyle Jul 2, 2013 2:28 PM (in response to John Hawkinson)John, thanks for the tip about var==true. I think sometimes I test for var==false, so I have a bad habit
But I don't get the idea of your snippet. What does
if (app.libraries && app.libraries.itemByName("Bob.indl")
test for?
-
4. Re: InDesign library: How is this possible?
RobertKyle Jul 2, 2013 2:28 PM (in response to suripappu)suripappu, I'm not looking for a simple count of libraries. I'm trying to determine whether a specific library (filename: Bob.indl) is currently open. I had thought that checking .isValid would do the trick, but there apparently is some in-between state where the library is open but its associatedPanel is not.
-
5. Re: InDesign library: How is this possible?
John Hawkinson Jul 2, 2013 2:31 PM (in response to RobertKyle)John, thanks for the tip about var==true. I think sometimes I test for var==false, so I have a bad habit
Indeed, you're better off with if (!var) ... in that case.
But I don't get the idea of your snippet. What does
if (app.libraries && app.libraries.itemByName("Bob.indl")
test for?
Test that app.libraries is an object before calling app.librarites.itemByName. (This is probably unnecessary.)
But then test that app.libraries.itemByName("Bob.indl") returns something, before trying to dereference it. Because if it returns null, then you will evaluate null.isValid, and that will generate an error.
-
6. Re: InDesign library: How is this possible?
RobertKyle Jul 2, 2013 3:18 PM (in response to John Hawkinson)Well,
app.libraries.itemByName("nonesuch.indl").isValid;
returns a nice, neat false if that library isn't open.
But I get the gist of it.
My real problem comes in the next step. If the library isVald, I'm trying to bring the associatedPanel to the front. But there is this odd case where the library isValid but the associatedPanel does not exist and can't be addressed. In a nutshell:
app.libraries.itemByName("Bob.indl").isValid; // true
app.libraries.itemByName("Bob.indl").associatedPanel.isValid; // true
app.libraries.itemByName("Bob.indl").associatedPanel.visible=false;
app.libraries.itemByName("Bob.indl").isValid; // false
app.libraries.itemByName("Bob.indl").associatedPanel.isValid; // error: Object is invalid
In real life, I don't make the panel invisible (it seems that that makes ALL libraries invisible if they are docked together). But imagine what happens if line 4 returns true. I can't reproduce it, but somehow the InDesign users in my office are getting into that position. I saw it on another guy's PC for a few minutes the other day and it looked like this:
app.libraries.itemByName("Bob.indl").isValid; // true
app.libraries.itemByName("Bob.indl").associatedPanel.isValid; // error: Object is invalid
app.libraries.itemByName("Bob.indl").assets.length; // 0
So the library is open but the window doesn't exist and it has no assets.
Is it a bug in the scripting model if associatedPanel.isValid returns true but not false?



