Re: Do shell script and special characters
Re: Do shell script and special characters
- Subject: Re: Do shell script and special characters
- From: Simon Kornblith <email@hidden>
- Date: Mon, 21 Oct 2002 18:54:55 -0400
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 10/21/02 3:02 PM, "Chris Espinosa" <email@hidden> typed away on his (or
her or its) keyboard producing the following output:
>
- Don't use shell commands to produce Mac-encoded text for return to
>
AppleScript. Use AppleScript's file read/write OSAXen, which are
>
designed to read Mac text files and return Mac formatted strings to
>
AppleScript.
What about when actual shell commands return ASCII strings? In the case of
my AppleScript application, this means that secure data needs to be written
to the disk. I know that I can delete it with "rm -P" and completely wipe
it out, but this is still quite annoying.
>
- If you want to capture the output of a shell command that is not
>
guaranteed to produce UTF-8, postprocess it by piping it through vis -o
>
to get an escaped UTF-8 form. You can unescape it with unvis,
>
Unfortunately there's no shell commands for translating MacRoman to
>
UTF-8 or back.
ASCII to UTF8:
native2ascii | native2ascii -reverse -encoding UTF8
UTF8 to ASCII:
native2ascii -encoding UTF8 | native2ascii -reverse
MacRoman to UTF8:
native2ascii -encoding MacRoman | native2ascii -reverse -encoding UTF8
UTF8 to MacRoman:
native2ascii -encoding UTF8 | native2ascii -reverse -encoding MacRoman
Unfortunately, on my machine this takes almost a second per conversion,
probably because native2ascii appears to be a Java app.
>
If you want this bug fixed by this time next year (by our "shady" team
>
that actually does "give a damn") then I'd appreciate some
>
recommendations from you on what specific behavior you want when a
>
shell command produces illegal UTF-8 to be returned to AppleScript in a
>
string variable:
>
>
- Translate all illegal UTF-8 characters into "missing character"
>
symbols, a la what the Terminal does? (This is lossy and irreversable,
>
but won't error)
This is pointless in most cases. If you're going to implement something
like this, implement it right.
>
- Assume that an error in coercing shell output to styled text means
>
that it's supposed to be in current text encoding? (This will produce
>
unpredictable results on non-MacRoman files; sometimes you'll get one
>
form, sometimes another, depending on what data is in the file)
In addition, this will produce unpredictable results on MacRoman files
since sometimes they may appear to be UTF8. This is what happened to quite
a few of my scripts when the AppleScript team decided to switch the default
behavior. Why not just let the user coerce with "as <<class utf8>>" (I
think) from plain ASCII? Better yet, add an interface to Text Encoding
Converter and let the script use that _after_ do shell script returns.
>
- Allow an 'as' or 'encoding' parameter on do shell script so you can
>
specify what encoding, if any, you expect the result to be in if it's
>
not UTF-8 (this would include 'as data' so you could, for instance, cat
>
a .jpeg file and get the raw .jpeg in an AppleScript data object)
This is probably the best solution. However, it still doesn't let a user
specify whether the input will be encoded UTF8 or not. This wouldn't matter
much, but I have several scripts that pass stdin through do shell script to
avoid writing to the disk and there's no way to pass stdin with the current
version of do shell script.
Simon
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (Darwin)
Comment: EntourageGPG - <
http://entouragegpg.sf.net/>
iD8DBQE9tIXKZoUZrWul2vIRAox4AKDPJ6lQfOmlVSxt9rEq1+Rw68ILhgCg2zYB
2fyDknG3DKIEa/ePkrY1aBU=
=dY+G
-----END PGP SIGNATURE-----
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.