Re: from Hex to string

p “66726f6d 70736e20”.scan(/\w\w/).inject(’’) {|s, b| s << b.hex.chr}
=> "frompsn "

cheers

Simon

Kroeger, Simon (ext) [email protected] wrote:

p “66726f6d 70736e20”.scan(/\w\w/).inject(‘’) {|s, b| s << b.hex.chr}
=> "frompsn "

fine, i do have about the same to translate into string.
this comes from event.data (event being a NSAppleEventDescriptor in
cocoa/MacOS X)

this is followed by :
“00000008 00000000”
which would have to be the psn number of the application having send the
event (i need this psn number in order to know which application is of
concern)

i know, because it’s me having type an url into safari, by ps -ax giving
:

1347 ?? S 0:05.34 /Applications/Safari.app/Contents/MacOS/Safari
-psn_0_6029313

that, the psn number is “6029313” being an odd number, “00000008
00000000” an even number, afaik.

how could i convert that part “00000008 00000000” into an integer ?

i’ve make use of :
keyword = 'addrpsn '.unpack(‘N’).first
sign=event.paramDescriptorForKeyword(keyword)
p “sign.class = #{sign.class} - paramDescriptorForKeyword”
=> “sign.class = NilClass - paramDescriptorForKeyword”
sign=event.descriptorForKeyword(keyword)
p “sign.class = #{sign.class} - descriptorForKeyword”
=> “sign.class = NilClass - paramDescriptorForKeyword”

which would be the “proper” way to get the psn number but always fails
into nil class…

instead of doing that by scan, gsub etc…

however it appears to me NSAppleEventDescriptor don’t give any way to
get pid, psn nor sign of the application having send this event : the
reason why, as a workaround, i 'm using this sort of hacking ))