Currency Converter Tutorial Help

I’m new to Applescript so I thought I would start out with the Currency Converter Tutorial in the Applescript Studio Programming Guide. I completed the exercise but my script is not working correctly.

the code is (from page 114):

on clicked theObject
tell window of theObject
set theRate to contents of text field “rate” as number
>>>set theAmount to contents of text field “amount” as number<<<
set contents of text field “total” to theRate * theAmount
on error
set contents of text field “total” to 0
end try
end tell
end clicked

The variable theRate works correctly but the variable theAmount is failing because it is not defined. I thought it may be a scoping issue so I defined the variable theAmount as a global but it changed nothing. I double checked the name of the control. The problem is with the “contents of text field “amount” as number” is not returning a value. Why? What basic element am I missing?

Thanks in advance

Hi and welcome.

Please post Xcode questions into the appropriate forum :slight_smile:

Have you named the text field “amount” in Interface Builder > Inspector > tab AppleScript?

Thanks Stephan

Were should I post this kind of question?

Yes, the amount name is correct.


The Xcode forum is fine, some helping hand has moved the thread form OS X to the Xcode section. :wink:

I recommend to compare your project with the working one at /Developer/Examples/AppleScript Studio/Currency Converter/

Thanks Stephan

I copied the applescript code and I still have an issue so the code is not the problem.

I then compared the attributes on the controls (NSTextboxes) and nothing jumps out at me, they look the same.

This line works: set theAmount to 23
This line doesn’t: set theAmount to contents of text field “amount”

Looks like the textbox “amount” doesn’t exist but I know it does.

I’m sure not off to a good start.

the AppleScript Code is not the problem.
Please check your connections in Interface Builder against the connections of the given example.
I’m sure, there’s a reference (like a name) missing


I couldn’t find a name missing but I did get a little further down the trail. :slight_smile: The issue seems to be the number formatter. When I delete it, the calculation works. When I add the Number Formatter and set to Currency, the conversion fails. I’m dragging the Number Formatter on to the text box and setting the Style to Currency. Is there some secret to setting up the Number Formatter?

Thanks again


Well, I finally found the issue. I was setting the Number Formatter to Mac X OS 10.4+ because I have Leopard. That apparently does not work.

When I select Mac X OS 10.0+ it starts working.

Can you tell me why this is an issue?

Thanks for all your help.