Mailing Lists: Apple Mailing Lists

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

AS and Unicode characters



Hello

Trying to help a friend, I wrote a script trying to grab an UNICODE character starting from its hexadecimal code.

This short script

-- [SCRIPT]
on getUnicode(h)
  local t, f
  if (count of h) = 1 then
  set h to "000" & h
  else if (count of h) = 2 then
  set h to "00" & h
  else if (count of h) is in {3, 5} then
  set h to "0" & h
  end if
  set t to ((path to desktop) as text) & "tempk"
  set f to open for access file t with write permission
  set eof of f to 0
  write (ASCII character 254) & ¬
  (ASCII character 255) & ¬
  (ASCII character (my decimal(h's text 1 thru 2))) & ¬
  (ASCII character (my decimal(h's text 3 thru 4))) to f
  if (count of h) > 4 then write (ASCII character (my decimal(h's
text 5 thru 6))) to f
  close access f
  set the clipboard to (read (t as alias) as Unicode text)
end getUnicode

on decimal(h)
local p
  set p to "0123456789ABCDEF"
  return ((offset of (h's character 1) in p) - 1) * 16 + ¬
  (offset of (h's character 2) in p) - 1
end decimal

my getUnicode("1D12B")

(* FE FF 01 D1 2B *)
-- [/SCRIPT]
seemed OK as it correctly writes the sequence "FE FF 01 D1 2B" in the temporary file.


Alas, when pasting in TextEdit I discovered that the code only grabbed the first two bytes 01D1 giving to me an infamous
(LATIN CAPITAL LETTER O WITH CARON whose code is (01D1)
when I wanted a
MUSICAL SYMBOL DOUBLE FLAT (01D12B).


Is one of you aware of some workaround?

Yvan KOENIG

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

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.