Hello all!
I’m new to this forum, I’m a software developer. I had been working with Java but I just started to code for iOS devices so I needed to change my old computer for a Mac.
The problem at this moment is that I had been using excel to make my, hum… quotation (I guess that’s the word, my mother language is Spanish), and even when I have mostly translated all my usual formulas to numbers, there is one function I’m still missing. The thing is that I coded thas specific function as a macro in VBA, and numbers (AFAIK) can’t use macros.
So I need to convert a given figure to it’s word equivalent. I might say that there are some places over the Internet that you can do that and just copy and paste the result, but I thought that this was the perfect oportunity to learn some basics about Applescript, sadly I’m far from done.
I have been searching ways to do this, and found a specific function:
on convertNumberToWords(thisNumber)
tell current application's NSNumberFormatter to ¬
set resultingText to localizedStringFromNumber_numberStyle_(thisNumber, current application's NSNumberFormatterSpellOutStyle)
return (resultingText as string)
end convertNumberToWords
For what I read this is ASOC (AppleScript with Objective C), but when I call this function it send me this message:
error “NSNumberFormatter no entiende el mensaje “localizedStringFromNumber_numberStyle_”.” number -1708 from NSNumberFormatter (The Spanish part is: “Can’t understand the message”)
And that may be right, because at least for iOS that function is:
(NSString * nonnull)localizedStringFromNumber:(NSNumber * nonnull)num
numberStyle:(NSNumberFormatterStyle)localizationStyle
But it seems that I can’t call this function this way either. By the way, I tryied this with Automator as a work flow, but then I read that when I call ObjC from a script I need to save this as a Script Bundle and check AppleScript/Objective-C Library checkbox so for that I used the AppleScript Editor, so the next problem I can foresee is that I don’t have any idea how to use this as a service as I did with Automator, but I guess I need to read more about that later, but be prepared for more questions if I can’t solve that either
When I discovered this forum, the first thing I did was searching for the full answer, an I found this topic: http://macscripter.net/viewtopic.php?id=32033
Nevertheless I’m still intrigued about how to call Objective C functions from a script, and use them as services. So if anyone can shed a little light on this matter I’ll be glad and very thankful.
Model: iMac 27-inch, Late 2013
AppleScript: 2.3.2
Browser: Chrome 43.0.2357.124
Operating System: Mac OS X (10.9)