• 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: Converting AppleScript Routine to shell, how to write BOM to beginning of file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting AppleScript Routine to shell, how to write BOM to beginning of file?


  • Subject: Re: Converting AppleScript Routine to shell, how to write BOM to beginning of file?
  • From: "Mark J. Reed" <email@hidden>
  • Date: Fri, 24 Aug 2007 15:52:12 -0400

A brief terminology clarification: the BOM is by definition one
"character".  When encoded as UTF-8, it is represented by three bytes
with the decimal values you gave.  The AppleScript term "ASCII
character" is thus doubly a misnomer here.

In bash you can output arbitrary bytes by using the -e ("honor Escape
sequences") option to the echo command and putting backslash octal
escapes in the string.  Decimal 239 is octal 357;decimal 187 is octal
273; and decimal 191 is octal 277.  So you can output a BOM with this
command:

echo -ne '\357\273\277'

(The -n prevents echo from adding a newline after the bom)

On 8/24/07, Richard Rönnbäck <email@hidden> wrote:
>
> I am converting an AppleScript solution to something that more heavily
> relies on shell scripting and one of the problems I have stumbled upon is
> how to create UTF-8 encoded files with a leading BOM.
>
> The stuff I am writing, either as the output of shell commands, or stored in
> variables, is already UTF-8, so the encoding is right, but if I try to just
> write it to file, like this
>
>     $myContent >/somefile.txt
>
> then obviously it has no BOM. In AppleScript I created (with kind assistance
> by people on this list) the BOM by combining these three characters:
>
>     set myBom to ((ASCII character 239) & (ASCII character 187) & (ASCII
>
> When written as UTF-8 they become a BOM.
>
> However, now that I am writing my ShellScript I am using BBEdit and if I try
> to do she same trick I have to use MacRoman Encoding for the script,
> something I really like to avoid. I would prefer UTF-8 encoding, but if I
> switch to UTF-8 encoding it no longer works.
>
> Can someone help me with a shell UTF-8 way of creating the BOM?
>
>
> Thanks in advance
>
>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>


--
Mark J. Reed <email@hidden>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Converting AppleScript Routine to shell, how to write BOM to beginning of file?
      • From: Richard Rönnbäck <email@hidden>
References: 
 >Converting AppleScript Routine to shell, how to write BOM to beginning of file? (From: Richard Rönnbäck <email@hidden>)

  • Prev by Date: Resizing in Photoshop
  • Next by Date: Re: Reading and writing records
  • Previous by thread: Converting AppleScript Routine to shell, how to write BOM to beginning of file?
  • Next by thread: Re: Converting AppleScript Routine to shell, how to write BOM to beginning of file?
  • Index(es):
    • Date
    • Thread