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.
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)
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.
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:
on clicked theObject
tell window of the theObject
set Caption to contents of text field "imageCaption" as string
tell application "GraphicConverter"
set IPTC caption of window 1 to Caption
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.