Hi,
I have scripted fairly extensively in Applescript and am familiar with the Standard Additions read/write commands. However, I have run into a stumbling block in reading a file in OS X as hexadecimal. Does anyone know if it is possible and what the syntax is? I have tried both:
set fileHeader to read openedFile from 0 to 20 as hex
and
set fileHeader to read openedFile from 0 to 20 as hexadecimal
where fileHeader is the file reference created by:
set openedFile to open for access (choose file)
I can’t seem to get hex or hexadecimal recognized as a data type in OS X, where OS 9 was no problem.
set h to "48656C6C6F2C20446F6C6C79"
hextoString(h)
--stringtoHex(result) = h
on stringtoHex(this_string)
this_string as C string
try
result * 5
on error msg
return text from character 22 of msg to character -19 of msg
end try
end stringtoHex
on hextoString(t)
set z to ""
repeat with i from 1 to t's length by 252
try
set z to z & (run script "«data cstr" & ¬
text from character i of t to character (i + 251) of t & "00» as string")
on error
set z to z & (run script "«data cstr" & ¬
text from character i of t to character -1 of t & "00» as string")
end try
end repeat
z
end hextoString