Unicode, huh???? Need help with coercion to string

Hello People Much Smarter Than Me (PMSTM or pa-mis-tum),

I am having trouble turning Unicode text into a string. Ok, not so much a problem as impossibility (for me that is). I have looked over old posts and found topics that look similar, but when I try to apply these to my situation I get the same error message (Data of wrong type) or different error that sends me into daydreams of throwing office chairs through computer screens, kicking my boss in the shin, or striping naked, sitting in the corner, and rocking back and forth as I stare blankly at the book AppleScript for Applications.

The problem:
I’m trying to create a simple window with several text fields (using AppleScript Studio) that tells GraphicConverter to set the Image Info (in the IPTC header) of a photograph.
What doesn’t work:

set imageCaption to contents of text field "Caption" as string

Any help would greatly appreciated (and cut down on my shrink bill)

Thanks, Chris

have to tried to set it to a static string

set imageCaption to “this is a test” as string
if that works then the problem is the field

– try the full object path
set imageCaption to contents of text field “Caption” of window “main”

I am assuming you are using the
tell application “GraphicConverter”
end tell

to make text unicode text
set imageCaption to “this is a test” as Unicode text
display dialog imageCaption

and back
set myText to (imageCaption) as string
display dialog myText

if you are using applescript 1.5.5 or later the output would be “this is a test”
pre 1.5.5 <<data utxt(encoded characters)>>

hopefully you’ll find something useful in my rantings


I think that your problem is not in coercing unicode text to a string, but in the way you are referencing your text field. Can I assume that the code that you provided below is in an “on clicked” handler? Also can I assume that the text field is on the same window as the button? If so i then try the following code that make a full reference to the text field.

set imageCaption to contents of text field "Caption" of window of theObject as string

As you see you need to tell the script which window that the text field is in. I hope this helps. If my assumptions are incorrect, then post back and maybe include the error message so we can have some more clues.


arcnon and Ross,

First, thank you both for your timley response. It was nice, after posting at 5 a.m. (Colorado here), to sit down at work and find clues.

Next, arcnon I have tried a static string and using display dialog Caption. Both work as they should. Ross, here is the orignal code:

global Caption

on clicked theObject
	tell window of the theObject
		set Caption to contents of text field "imageCaption" as string
	end tell
	tell application "GraphicConverter"
		set IPTC caption of window 1 to Caption
	end tell
end clicked

I tried set Caption to contents of text field “imageCaption” of window of theObject as string and received the same error message: “GraphicConverter got an error: Some data was the wrong type. (-1703)”

IPTC headers are international text, however; when I use:

display dialog "Caption:" default answer "" 
set Caption to text returned of the result

followed by the GraphicConverter tell statement everything works fine. Also, and stangly enough, if I leave the “imageCaption” text field blank the Caption field of the IPTC header is set to nothing and there is no error.


Thanks again for your help,

Try using a different variable name as “caption” is probably a reserved word in GraphicConverter:


[This script was automatically tagged for color coded syntax by Script to Markup Code]