Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

osascript gotcha: text encoding incompatibility



Various past posts have recommended using osascript as a way to invoke AppleScript
from Java. I have used this technique many times with apparent success. However, I just
discovered a problem: conflicting text encodings when passing command line arguments.
The upshot is that many of the simple examples shown in past posts will fail when used
with a filename containing non-ASCII characters.


The problem: When using Runtime.exec, Java encodes command line
arguments using UTF-8. When AppleScript decodes command line arguments, it
uses MacRoman. If your command line argument contains non-ASCII characters,
it will probably be garbled. (The same is true for environment variables.)

I am not aware of any way to alter the encoding used
either by Java or AppleScript on this path. Does anyone know of one?

The only workaround I know of is to pass text (including file names) in temporary files,
which allows the encoding to be controlled at both ends. For details on the AppleScript
end, see:


http://www.satimage.fr/software/en/unicode_and_applescript.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.