0


I'm coding a little app that asks a question using display dialog with default answer "", takes whatever the user input is (let's say die Universität), and sends it to a Python file. Python checks the spelling of the word, translates it, spits out a display dialog with the English translation.
The problem I'm having is that Applescript is not giving Python a nice encoding. Here's my code in Applescript:

set phrase to the text returned of (display dialog "Enter German Phrase" default answer "")
set command to "python /Users/Eli/Documents/Alias\\ Scripts/gm_en.py " & phrase
do shell script command

I get the input into Python. It's breaking everything, so I'm using chardet to figure out what the encoding is. It's giving me this: {'confidence': 0.7696762680042672, 'encoding': 'ISO-8859-2'} Not only is this pretty innacurrate, it's an encoding I can find very little about online. Trying to convert with decode('iso-8859-2') gives very strange symbols.
Any ideas?

Eli Berkowitz
  • 299
  • 3
  • 12
  • Use [UTF8](https://developer.apple.com/library/mac/technotes/tn2065/_index.html#//apple_ref/doc/uid/DTS10003093-CH1-SECTION3). – foo Feb 26 '16 at 15:43
  • `UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)` – Eli Berkowitz Feb 26 '16 at 16:38
  • 1
    Python 2's `str` vs `unicode` division is a PITA. [See here](http://stackoverflow.com/a/27425797/2298645) for how to read and write stdin/stdout as UTF8, [and here](http://stackoverflow.com/a/14028665/2298645) for how to read argv likewise. Oh, and while you're at it, you also must use `quoted form of phrase` on line 2 of your AppleScript, otherwise your shell script is going to explode the moment the phrase contains spaces or other 'special' shell characters. – foo Feb 26 '16 at 18:39

0 Answers0