2

I'm facing a problem when trying to call AppleScript (MacScript) to read out aloud non-Latin characters from VBA on Mac Excel 2011 (e.g. text in specific Excel cells). The following code line is working fine to read French text using the synthetic voice "Audrey":

MacScript ("say """ & FrenchStrg & """ using ""Audrey""")

FrenchStrg e.g. "croissant"

However, when trying to use the same code for Greek using the synthetic voice "Nikos", as in

MacScript ("say """ & GreekStrg & """ using ""Nikos""")

GreekStrg e.g. "ούζο"

most of the string (in Greek characters) is interpreted as "_" and is therefore not read aloud (the command "say "ούζο" using "Nikos"" is working fine in the AppleScript editor). In some cases, a few letters may be interpreted as some special character and are read out accordingly, but I couldn't find a useful pattern.

When changing the standard language of Mac OsX from English to Greek, the characters are correctly recognized within the VBA editor and in a MsgBox. However, the output to MacScript is still not working. Does the VBA MacScript function only accept non-unicode text? Is there any solution?

Any help would be much appreciated!

Ivo Meyer
  • 31
  • 5

2 Answers2

1

Thank you @Zero for suggesting to use the clipboard. This did indeed solve the problem. Here is the final working code:

Cells(1, 1).Copy
MacScript ("say (the clipboard) using ""Nikos""")

This circumvents the problem of strings getting converted into non-unicode text.

Ivo Meyer
  • 31
  • 5
0

I don't think this will work but to be sure you should try it anyway:

MacScript ("say """ & (GreekStrg as Unicode text) & """ using ""Nikos""")

Unicode Support
AppleScript is now entirely Unicode-based. Comments and text constants in scripts may contain any Unicode characters, and all text processing is done in Unicode, so all characters are preserved correctly regardless of the user’s language preferences. For example, this script works correctly in AppleScript 2.0, where it would not have in previous versions:

set the Japanese_phrase to "日本語"
set the Russian_phrase to "Русский"
set the new_phrase to the Japanese_phrase & " and " & the Russian_phrase
return new_phrase
  • 1
    I believe the VBA for `(GreekStrg as Unicode text)` would be `StrConv(GreekStrg, vbUnicode)`. – Comintern Apr 17 '15 at 04:19
  • 1
    Thanks for the answers. I tried both methods, but they don't seem to work. `GreekStrg as Unicode text` is useless, as the MacScript VBA function already uses a meaningless string as input ("____"). Though accoding to Office Support "vbUnicode" is not available on Mac, StrConv did do something to the string, though not what I expected. Using the MacScript `display dialog` command, the string "αβγδεζηθικλμνξοπρςστυφχψω" is displayed either as "_______________π_________" or as "±__´µ¶·¸_º»___¿ÀÁÂÃÄÅÆÇÈÉ", if `StrConv(GreekStrg, vbUnicode)` is used. @Zero @Comintern – Ivo Meyer Apr 17 '15 at 15:09
  • You could try to copy the cell's text and use the clipboard to speak it or something like that. Check Excel's scripting dictionary (open the app with Script-Editor), maybe there is something interesting that helps! –  Apr 17 '15 at 16:36
  • Some text I just found here ( http://answers.microsoft.com/en-us/mac/forum/macoffice2011-macexcel/vba-code-for-excel-2011-for-mac-vba-macro-code-to/211913d6-deb9-4754-b112-e866a4b92d0b ): "Office 98 and earlier had a macro for this purpose (speak). In Office 2011 all you do is select whatever you want to hear and press the keyboard shortcut you assigned speak text to in System Preferences. " -- –  Apr 17 '15 at 16:48