• 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: Producing Unicode-only characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Producing Unicode-only characters


  • Subject: Re: Producing Unicode-only characters
  • From: "Nigel Garvey" <email@hidden>
  • Date: Tue, 25 Oct 2005 23:01:06 +0100

has wrote on Tue, 25 Oct 2005 13:30:41 +0100:

>kai wrote:
>
>>One method that I've been using to produce Unicode-only characters is:
>>
>>---------------
>>
>>«data utxt3048» as Unicode text
>>
>>---------------
>>
>>While this seems to be substantially faster than using a shell
>>script, I'm just wondering if there's a potential downside...
>
>Known problems are:
>- crap readability
>- doesn't work pre-Panther (and can result in crashes).

There's a couple of 'run script' variants that work in Jaguar. One is:

  script
    «data utxt3048»
  end script
  run script result

This works in Tiger to, but can take about 2190 times as long as kai's
suggestion! A bit faster is the string version:

  run script "«data utxt3048»"

... which of course makes a nice basis for a Unicode character handler:

  on unicodeCharacter(n)
    run script "«data utxt" & {n div 4096, n mod 4096 div 256, n mod 256
div 16, n mod 16} & "»"
  end unicodeCharacter

  unicodeCharacter(12360)

You could arrange for the above handler to take a hexadecimal string instead.

I can't find a really satisfactory way to get the number from the
character, though there are two that are much faster than Chris's shell
script. The faster of the two exploits the single-record-list-to-string
coercion bug, which still exists in Tiger:

  on unicodeNumber(c)
    set s to {{a:character 1 of c}} as string
    (ASCII number (character -2 of s)) * 256 + (ASCII number (character -
1 of s))
  end unicodeNumber

Otherwise, as Chris mentioned, there's the temporary file approach. You
need to set a suitable location for the file and perhaps delete it after use:

  on unicodeNumber(c)
    set fref to (open for access file ((path to desktop as Unicode text)
& "Utxt chr.txt") with write permission)
    try
      set eof fref to 0
      write character 1 of c to fref
      set n to read fref as short integer from 1
    end try
    close access fref

    return n
  end unicodeNumber


NG

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Producing Unicode-only characters
      • From: Emmanuel <email@hidden>
    • Re: Producing Unicode-only characters
      • From: Dave Lyons <email@hidden>
    • Re: Producing Unicode-only characters
      • From: kai <email@hidden>
    • Re: Producing Unicode-only characters
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: [appscript] looking for feedback
  • Next by Date: Re: QuickTime - Save Export Settings - script help needed
  • Previous by thread: Re: Producing Unicode-only characters
  • Next by thread: Re: Producing Unicode-only characters
  • Index(es):
    • Date
    • Thread