0 Replies Latest reply on Feb 2, 2011 11:49 AM by torgo-a

    Strange behavior of name "ends with" when finding layers in AppleScript.


      I ran into an odd situation while fixing a problem with some automation software I'm in charge of. I'm not sure if it's a bug (like it appears to be to me), or if Adobe just has an interesting definition of how the "ends with" clause should behave.

      The situation is this: My software needs to show all layers where the layer name ends with "_tap test". The script snippet that does this was pretty straightforward:


      set visible of every layer whose name ends with "_tap test" to true


      This ended up making layers visible that were quite unexpected.

      But what I found (by making a small test script and changing it to give me the name of every layer whose name ends with "_tap test") was that I was getting back multiple, completely incorrect layers. Through some experimentation, it appears that when the "ends with" value starts with an underscore, and has a space in it, it gives me back every layer whose name has the same number of non-whitespace characters as the "ends with" value. So for "_tap test" it would give me back every layer whose name was 8 characters long!

      To test this, I did the following:

      1. Make a new document.

      2. Make layers: "OE_tap test", "layer111", "alongnamedlayer", "layer222" and "short".

      3. Execute the script:

      tell application "Adobe InDesign CS5"

      tell document 1

      name of every layer whose (name ends with "_tap test")

      end tell

      end tell

      4. See that it returns the list {"Layer222", "Layer111", "OE_tap test"}

      5. Change the script so that it's ever name ends with "_xx hi"

      6. See that it now returns the string "short".

      7. Removing the space in the ends with value, or removing the underscore returns the "ends with" behavior to how one would expect.

      I've tried this in CS5, CS4, and CS3, on both OS X 10.6 and 10.5, with exactly the same results. Is there some super-secret meaning behind starting an "ends with" search value with an underscore that I missed, or this a crazy bug in InDesign? I've worked around the issue by just not putting the underscore in the script anymore, and alerting the people who make the documents that are processed to this change (it likely won't affect the workflow). But I'm still at a loss for why InDesign works this way.

      Any ideas or insight would be appreciated.