Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristoferK/074867338182d51e5ff249a2735f2450 to your computer and use it in GitHub Desktop.
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
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 |$|:
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