• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AS data types
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AS data types


  • Subject: Re: AS data types
  • From: Arthur J Knapp <email@hidden>
  • Date: Wed, 23 Jan 2002 15:00:04 -0500

> Date: Wed, 23 Jan 2002 14:19:51 -0500
> Subject: AS data types
> From: Michael Turner <email@hidden>

> Does AS provide any technique of reflection for data types (I think it
> is called that). I would like to ask a variable what data type it
> contains. Is this possible? Is there any way to know if I have a valid
> string?

I think you are looking for the "class" keyword:

set theClass to class of "Hello World" --> string
set theClass to class of 3.14159 --> real

You can read the AppleScript Language Guide for listings
of the available data types of AppleScript:


<http://developer.apple.com/techpubs/macosx/Carbon/interapplicationcomm/Appl
eScript/AppleScriptLangGuide/index.html>


P.S. Hackers Alert:

Often, the class returned can be deceptive, in that many
different types of underlying data types might return the
same class value.

Here is a handler for obtaining a more precise data type
identifier:


-- 1) Copy this script into your script editor.
-- 2) Compile, (but don't run).
-- 3) Copy the compiled text "Hello World" to the clipboard,
-- your script editor should place it there as styled text.
-- 4) Run the script.

on ClassCode(v)
(*
* HACK !!!
*)
({{p:v}} as string)'s text 39 thru 42
end ClassCode

set plainString to "Hello World" --> "Hello World"
set styledString to (the clipboard) --> "Hello World"

set plainString_class to class of plainString --> string
set styledString_class to class of styledString --> string

set plainString_code to ClassCode( plainString ) --> "TEXT"
set styledString_code to ClassCode( styledString ) --> "STXT"

plainString_class = styledString_class --> true
plainString_code = styledString_code --> false


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
(*) Happy
( ) Sad
( ) Ambivalent
( ) Ubiquitous
}


  • Prev by Date: Re: AS data types
  • Next by Date: Re: FMP Container
  • Previous by thread: Re: AS data types
  • Next by thread: Re: AS data types
  • Index(es):
    • Date
    • Thread