• 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: interesting discovery (trying to get record labels as strin
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: interesting discovery (trying to get record labels as strin


  • Subject: Re: interesting discovery (trying to get record labels as strin
  • From: Arthur J Knapp <email@hidden>
  • Date: Mon, 10 Dec 2001 19:27:24 -0500

> Subject: Re: interesting discovery (trying to get record labels as strin
> Date: Wed, 5 Dec 2001 14:10:40 +0000
> From: Nigel Garvey <email@hidden>


I was away for a while...


> Arthur J Knapp wrote on Tue, 04 Dec 2001 10:56:10 -0500:

>> on StringToCodes(str)
...

>> StringToCodes("Hello World")
>> --
>> --> {72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100}


> Even though it relies on a bug that's under threat of cure, this is
> totally brilliant! :-)

Thanks, Nigel. I know how hard it is for you to admit things
like that. ;-)


> The complementary routine might look something like this:
>
> on codesToString(codes)
>
> set str to {{a:codes as list}} as string
>
> set typeOffset to offset of "long" in str
> set typeStr to text typeOffset thru (typeOffset + 10) of str
>
> set o to text item delimiters
> set text item delimiters to {typeStr}
> set str to text items 2 thru -1 of str
> set text item delimiters to {""}
> set str to str as string
> set text item delimiters to o
>
> return str
>
> end codesToString
>
> codesToString({72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100})
> --> "Hello World"

Good stuff. :)

Here's something else:


property k0 : ASCII character 0
property k1 : ASCII character 1
property k2 : ASCII character 2
property k4 : ASCII character 4

property k0000 : k0 & k0 & k0 & k0
property k0001 : k0 & k0 & k0 & k1
property k0002 : k0 & k0 & k0 & k2
property k0004 : k0 & k0 & k0 & k4

on IntegerToBytes(n)
return ({{a:n}} as string)'s text -4 thru -1
end IntegerToBytes

on StringToHex(str)

set strLength to str's length

-- These structures seem to all be "padded" to an even length:
--
if (strLength mod 2 = 1) then
set str to str & k0
end if

-- The k0002 indicates their are two structures in the usrf,
-- the property text and the data itself. I don't know why
-- the item-count is always followed by a "long" zero, k0000.
--
-- Because the a in { a : ... } is an odd length, it gets padded
-- with Ascii 0.
--
set rawData to k0002 & k0000 & "TEXT" & k0001 & "a" & k0

-- So we append the second item, a "raw " class, followed by it's
-- data-size, followed by the string.
--
set rawData to rawData & "raw " & IntegerToBytes(strLength) & str

-- This data-size is for the entire usrf structure.
--
set dataSize to IntegerToBytes(rawData's length)

-- Prepend the "header" info, along with the dataSize
--
set rawData to k0001 & k0000 & "usrflist" & dataSize & rawData

set dataType to a of (rawData as record)

try
err of dataType
on error err
end try

-- Relies on the exact error message, "Can't get err of +data raw ..."
--
return err's text 28 thru -3

end StringToHex

StringToHex("Hello World")
--
--> "48656C6C6F20576F726C64"


Actually, I think their was another way to do this, something about
using a Unicode coercion, but this is pretty good too.

I'll leave it to my sidekick, NG, to provide the complementary routine...

;-)



{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.VivaLaData.com/>
on error number -128
end try
}


  • Prev by Date: Re: 9.2.2 Update effects on applescript
  • Next by Date: Re: Disappearing Script menu
  • Previous by thread: Re: interesting discovery (trying to get record labels as strin
  • Next by thread: Finder out of memory mystery...
  • Index(es):
    • Date
    • Thread