XAccessor Reference

XAccessor is an AppleScript library to make followings possible.

Example

use XAccessor : script "XAccessor"

set a_record to {a:"aa"}

script AScript
property a : "aa"
global b
on get_b()
return b
end get_b
end script

(*== Using Class Methods ==*)
(* access to property *)
log XAccessor's value_of(AScript, "a") -- "aa"
XAccessor's set_value(AScript, "a", "hello")

(* access to global variable *)
XAccessor's set_global("b", "hey")
log XAccessor's global_value("b") -- "hey"


(*== Using XAccessor Instance ==*)
(* access to property *)
set a_accessor to XAccessor's make_with("a")
log a_accessor's value_of(AScript) -- "hello"
log a_accessor's value_of(a_record) -- "aa"

(* access to global variable *)
set b_accessor to XAccessor's make_with("b")
log b_accessor's global_value() -- "hey"]

Description

The mechanism of XAccessor is making script objects to access properties at runtime using "e;run script"e; command.

Class methods always generate an accessor object each time when called. The cost of generating an accessor object is expensive. The number of generating accessor objects should be keep minimum. Therefor it should be considered that storing accessor objects returned from make_with(a_name) into variables, and reuse it.

Class Methods

value_of

Obtain a value in a record or a property of a script object with specify its label of a text.

set_value

Set a value in a record or a property of a script object with specifying its label of a text.

global_value

Obtain a value of a global variable specified with a name.

set_global

set a value to a global variable specified with a name.

Obtain an Accessor Object

make_with

Obtain an accessor object to access a label specified with a text.

Instance Methods

value_of

get value in an_object

set_value

set a value to the property of given object

global_value

Get a value of a global variable

set_global

Set a value to global variable