• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Do shell script and special characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do shell script and special characters


  • Subject: Re: Do shell script and special characters
  • From: John Delacour <email@hidden>
  • Date: Tue, 22 Oct 2002 18:58:27 +0100
  • Mac-eudora-version: 5.3a5

At 12:02 pm -0700 21/10/02, Chris Espinosa wrote:

Well, whether it's a "bug" or a design choice is subject to debate. By definition, shell I/O in Mac OS X is encoded in UTF-8. You can of course use shell commands to move or copy data between files and devices in any encoding and in raw form, but to send text to the shell or get output from it, the defined encoding is assumed to be UTF-8.

That's some assumption, since I've never met anyone who types UTF-8, so in order to send UTF-8 to anything I first need a tool convert macintosh to UTF-8 and that means using either the TEC Osax or Smile, since Apple provides no means for a user to perform these conversions.

I use do shell script mainly for perl and I want to be able to write a script in roughly the same way as I would normally; for example the following script will print a bullet.

#!/usr/bin/perl
$_ = qq~"\xA5"~ ;
print if /\xA5/ ;
# --> <bullet>

but if I put that into do shell script, I get nothing

set c to ASCII character 165 -- a mac bullet 0xA5
do shell script "perl -e '
$_ = qq~" & c & "~;
print if /\\xA5/
'"
--> ""

So I ask you, is the way things work really very useful? One of the great things about OS 10 is having perl built in, but Apple gives us no proper tools to use it and instead one has either to use commercial third party programs like BBEdit and Alpha or else write abstruse scripts to get round the difficulties.

Now if you were to add an event that would allow something like

do perl script to END_OF_SCRIPT
#!/usr/bin/perl
$_ = "\xA5" ;
print if /\xA5/ ;
END_OF_SCRIPT

it might look as if some consideration were being given to perl users, who don't want to do

- 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.

You will have seen from various previous postings that this is the way I have been working round it, but it's so long-winded and clumsy. Luckily it is not slow.

- 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.

There's no Apple tool at all for doing this.

- 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)

Advice welcome.

This seems to be the best solution, but since the system on one hand and 100% of its users on the other are talking and typing two different languages it would be good to have some simple interpreting tools built into AppleScript.

JD
_______________________________________________
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.

References: 
 >Re: Do shell script and special characters (From: Chris Espinosa <email@hidden>)

  • Prev by Date: Re: User Name in OS X +
  • Next by Date: Re: Exists statements
  • Previous by thread: Re: Do shell script and special characters
  • Next by thread: Re: Do shell script and special characters
  • Index(es):
    • Date
    • Thread