Re: Ed Lai's 'cast' osax lost in conversion from OS 9 to OS X - any ideas?
Re: Ed Lai's 'cast' osax lost in conversion from OS 9 to OS X - any ideas?
- Subject: Re: Ed Lai's 'cast' osax lost in conversion from OS 9 to OS X - any ideas?
- From: jj <email@hidden>
- Date: Wed, 15 Dec 2004 22:24:35 +0100
> I tried to search applescript-users, but there doesn¹t seem to be a searchable
> archive. It also seems that the Sherlock plugins for searching osaxen
> packages, additions, and commands on MacScripter.Net are not compatible with
> Sherlock 3, and I can¹t even figure out how to determine whether particular
> osaxen are OS X compatible.
You can search the archives of this list here:
http://search.lists.apple.com/
You can figure what osaxen are OS-X browsing Osaxen.com's main page (there
is a category labeled such ;-):
http://www.osaxen.com/
> tell application "Now Up-to-Date - OS X"
> tell event 1 of category 1 of document 1
> get contactlink of person 1
> «event sysoCAST» result given «class TO »:integer -- requires Ed
> Lai's Programmer's Tool scripting addition
> end tell
> set NCpersonID to result
> end tell
About your problem, some times apps can return raw data to AppleScript (in
particular, they return a bunch of unkown things instead of coercing to
integer the data internally). Being only an integer, it shouldn't be very
difficult fake a "cast". How does it look the data returned by
"contactlink"? Usually the structure is "data" + space + "type of data, a
four-byte identifier" + arbitrary hex data. Eg:
«data XXXX01F0»
As it only stores an integer, it should be easy converting the hex digits to
a number (if this is our lucky day). Eg:
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
set dataFromApp to «data KAKA00FF»
--> extract hex digits
set hexStuff to text 11 thru -2 of whateverToText(dataFromApp)
--> convert hex to decimal
set theNumber to HexToDec(hexStuff) --> 255
on whateverToText(x)
try
if class of x is in {string, Unicode text} then
try
count x
return x
on error msg --> handle data string/utxt
return text 1 thru -39 of msg
end try
else
tell application x to beep
end if
on error msg
set msg to text 23 thru -2 of msg
if msg starts with "(" and msg ends with ")" then --> unknown object
return text 2 thru -2 of msg
else
return msg
end if
end try
end whateverToText
to HexToDec(n)
set hexchars to "0123456789ABCDEF"
set n to n as string
--> uppercase some chars if needed
set uPP to "ABCDEFG"
set lWE to "abcdefg"
repeat with i from 1 to (count lWE)
set AppleScript's text item delimiters to (lWE's item i)
set n to n's text items
set AppleScript's text item delimiters to (uPP's item i)
set n to "" & n
end repeat
set AppleScript's text item delimiters to {""}
--> end uppercase
set n to reverse of (n's text items)
set theResult to 0
repeat with i from 1 to n's length
set theResult to theResult + ¬
(((offset of (n's item i) in hexchars) - 1) * (16 ^ (i - 1)))
end repeat
theResult
end HexToDec
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
jj
--
http://www.macscripter.net/
http://www.osaxen.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden