MACSCRPT Archives

January 2011

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Nigel Garvey <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Wed, 12 Jan 2011 09:29:40 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (59 lines)
"Mark J. Reed" wrote on Tue, 11 Jan 2011 13:17:57 -0500:

>On Tue, Jan 11, 2011 at 12:34 PM, John Delacour <[log in to unmask]> wrote:
>>
>>> Hey JD, you would probably know this procedure: I see a Unicode
>>> character on a Web page <http://www.ytn.co.kr/>, in this case a black
>>> triangle (like "[>"), and want to find out what code point it is. So
>>> I copied to the clipboard and wrote a script to try and convert it
>>> using something like this:
>>>
>>> item 1 of ((((theU as =C2=ABclass ut16=C2=BB) as string) as record) as l=
>ist)
>
>Yowza!
>Assuming you're in AS 2.0, all you need is this:
>
>id of (the clipboard as text)

Or, given that id returns a list if there's more than one character:

  id of character 1 of (the clipboard)


John Delacour wrote on Tue, 11 Jan 2011 17:34:24 +0000:

>set _clip to the clipboard
>set f to (path to temporary items from user domain as string) & "tmp.txt"
>try
>   close access file f
>end try
>open for access file f with write permission
>set eof file f to 0
>write _clip as Çclass ut16È to file f
>close access file f
>set _s to read file f as string
>set {_a, _b} to characters 3 through 4 of _s
>-- (the first 2 chars are the BOM)
>{ASCII number _a, ASCII number _b}
>--=> {186, 37}

I haven't been able to think of a better method for Tiger, but a more
streamlined version of the above would be:

  set _clip to character 1 of (the clipboard)
  set f to (path to temporary items from user domain as string) & "tmp.txt"
  set fRef to (open for access file f with write permission)
  try
    set eof fRef to 0
    write _clip to fRef as Unicode text
  end try
  close access fRef
  set _n to read file f as short
  --> 9654

This would of course require more code if you were likely to encounter
characters with more than two bytes.

NG

ATOM RSS1 RSS2