InDesign CS Master Spreads Fails in AppleScript Studio

I have an AppleScript Studio project that loads an external AppleScript which controls InDesign CS. When testing the IDCS controller script on its own, it works fine but when trying to use it from the AppleScript Studio app, it fails when trying to target a master spread whose name contains a string that is passed to it from the AS Studio app.

Here is the line in the controller that fails from AS Studio:

set targetMaster to first master spread of document docName whose name contains masterName

docName and masterName are sent to the controller’s handler from the AS Studio app. The AS Studio app receives this data from entry fields in the app’s UI.

I thought it might be a Unicode text to string problem and I’ve looked through Xcode documentation but I haven’t been able to find how to resolve this. I’ve used: (masterName as string) in both the AS Studio app and the InDesign Controller script (just to be sure) but neither works. I’ve also logged the class of the variable (while it is in the ID Controller script) and it shows up as string. I’ve also logged the class of the variable while it is still in the AS Studio app and it’s properly recorded as Unicode text. So the conversion is happening but it still isn’t working.

Does anyone have any idea why this might be failing?

Mac OS 10.3.8 - 10.3.9, InDesign CS 3.0.1, Xcode 1.0 - 1.1

Shane Stanley on the InDesign Scripting forum had the answer for me.

set x to «class ktxt» of (x as record)

Worked like a charm.