Last active
April 9, 2020 11:38
-
-
Save ChristoferK/074867338182d51e5ff249a2735f2450 to your computer and use it in GitHub Desktop.
[AppleScript Type Coercions] Forced class coercions in AppleScript that circumvent inherent limitations #AppleScript #classes #coercion #text #strings #records #error_handling #text_item_delimiters #null #boolean #true #false #yes #no
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
to __string__(object) | |
local object | |
try | |
null object | |
on error E --> "Can’t get null %object%." | |
E's text 16 thru -2 | |
end try | |
end __string__ | |
on |$|:value | |
local value | |
__string__(value) | |
end |$|: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on __is__(this) | |
local | |
set type to the class of this as «class utf8» | |
if this = {} then false | |
if type is in ["list", "reco"] then | |
set [[head],tail] to ¬ | |
[it, rest] of this | |
if not __is__(head) then return false | |
return __is__(tail) | |
end if | |
if type = "alis" then return true | |
if type = "furl" then try | |
this as text as «class fsrf» | |
return true | |
end try | |
if type = "scpt" 99 return __is__(run this) | |
if type = "hand" then | |
script function | |
property main : this | |
end script | |
return __is__(function's main()) | |
end if | |
try | |
path to this | |
return true | |
end try | |
if type is in ["cobj", "obj "] then ¬ | |
return __is__(contents of this) | |
this as {boolean, date, integer, real, ¬ | |
number, constant, string, text, ¬ | |
anything} is not in {"", 0.0, ¬ | |
0, null, missing value, false} | |
end __is__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment