Team LiB   Previous Section   Next Section
Memory Control Panel

Dictionary commands

close

This command closes the Memory control panel, as in:

tell app "Memory" to close

count reference

Use this property to count the elements of a class:

tell app "Memory" to count available disks

This code fragment returns the number of disks the computer could use for virtual memory. count returns an integer value. See the available disk class.

each type class

You can also use the syntax:

count each available disk

This usage returns the same value as:

count available disks

use default settings

If you use the following code, the control panel will set Disk cache, virtual memory, and RAM disk to default values (e.g., the default value for a RAM disk is "off "):

tell app "Memory" to use default settings

Dictionary classes

application

This class represents the Memory control panel. It has one element, available disk, as in:

get available disks

This returns a value that looks like:

{Disk Volume "Macintosh HD" of application "Memory", Disk Volume 

"H2gig" of application "Memory", Disk Volume "HB2gig" of application "Memory",

Disk Volume "scratch" of application "Memory"}

The Memory application can also get or set various features of disk caches, virtual memory, and RAM disks. This code example finds out the state of virtual memory (active if VM is enabled on one of the local disks) and the size of VM:

tell application "Memory"

   set VMOn to state of virtual memory

   set VMsize to size of virtual memory

   display dialog "The state of VM on this machine is: " & VMOn &¬

   return  & "The size of VM is: " & (VMsize / 1024 / 1024)

end tell

The following are application elements:

available disk

This class represents a disk that can be used for virtual memory. Get a list type containing references to the computer's available disks with this code:

tell app "Memory" to get available disks

See the available disk class.

The following are application properties:

disk cache disk cache settings

This is a property of the Memory application, but a script cannot get a return value for disk cache in the usual manner. In other words, you cannot use the syntax:

get disk cache

You have to use the code (an example return value is active):

get state of disk cache

or the following code (which returns the number of bytes in the system's disk cache):

get size of disk cache

These are settable attributes, so a script can change the state of a disk cache:

set state of disk cache to inactive after restart

or, a script could set the size of the disk cache to a new value:

set size of disk cache to ((size of disk cache) + (1024 * 1024))

This code adds a megabyte to the size of the disk cache. See the disk cache settings class.

frontmost boolean (read-only)

If frontmost is true, then the Memory control panel is the active application on the desktop.

name international text (read-only)

This property returns the name of the application as a string ("Memory").

RAM disk RAM disk settings

The RAM disk property returns a RAM disk settings object, which cannot be referenced directly in your script. In other words, the following syntax raises a script error:

tell app "Memory" to get RAM disk

The script has to use syntax such as:

get state of RAM disk or get persistence of RAM disk

The latter code gets a boolean value referring to whether the contents of the RAM disk will be saved if the computer is shut down. See the RAM disk class description.

version version (read-only)

This property returns a string (the version object return value is implemented as a string) that represents the Memory application version, as in "8.1.1."

virtual memory virtual memory settings

virtual memory returns the VM settings for the computer. You can reference these settings in the following manner:

tell app "Memory" to get size of virtual memory (* or get configured volume of virtual memory *)

If you try to access the VM settings directly, as in the following, the script raises an error:

get virtual memory

See the virtual memory settings class description.

available disk

This class represents a disk that can be used for storing virtual memory. For example, the Memory application object has available disk elements. You can access the disks that the machine can use for virtual memory with code such as:

tell app "Memory" to get available disks

The example at the end of the property definitions gets all the properties of the available disk that the machine is currently using for virtual memory. The script first tests whether virtual memory is active (turned on). If it is, then the available disk that is holding virtual memory storage is accessed with the following code:

set vmdisk to configured volume of virtual memory

One way to view the property values of the available disk is in Script Editor's Event Log window. See Chapter 2, for details on the Event Log, and see the virtual memory settings class description.

The following are available disk properties:

capacity double integer (read-only)

This property returns the maximum number of bytes that can be stored on the disk. The Memory dictionary identifies the return-value data type as "double integer," but AppleScripters will recognize it as a real type, such as 2.121269248E+9.

creation date date (read-only)

This property returns the creation date of the disk volume or partition as a date type that looks like:

date "Friday, July 16, 1999 1:59:29 PM"

free space double integer (read-only)

The free space of the disk holding virtual memory is the number of bytes not being used. An example return value is 1.494134784E+9. Apple Computer recommends that the disk used for VM have a free space equal to the total amount of VM you want to use plus the amount of physical RAM installed on the machine. You should always have a little bit more VM than physical RAM, so if your machine has 150 MB of memory, then the VM amount could be 151 MB, which requires a total of 301 MB of free space. Find out whether you have optimum free space on a VM disk with code, such as:

get free space of virtual memory's configured volume

This code has to be enclosed in a tell statement targeting the Memory application.

ID integer (read-only)

The ID property is a unique integer that identifies each disk, such as -3.

modification date date (read-only)

This property returns the modification date of the disk volume or partition as a date type that looks like:

date "Friday, July 16, 2000 2:59:29 PM"

name international text (read-only)

You can get the name of the disk with the following code fragment:

get name of (configured volume of virtual memory)

The name is returned as a string, such as "MyDisk."

startup boolean (read-only)

If the available disk object is the machine's startup disk, or the disk the machine was booted up from, then this property returns true. A script can access this property with code such as:

(* this example gets a lot of virtual-memory property values *)

tell application "Memory" 

   set isStartup to (startup of (configured volume of virtual memory))

   if state of virtual memory is active then -- find out whether VM is on

      (* if VM is on, get a reference to the disk storing the VM *)

      set vmdisk to configured volume of virtual memory

      set proplist to {vmdisk's name, vmdisk's ID, vmdisk's¬ 

     creation  date, vmdisk's modification date, vmdisk's¬

     capacity, vmdisk's free space, vmdisk's startup}

   else

      display dialog "Virtual memory is not active right now!"

   end if

end tell

(* Sample return value *)

{"HFSB2gig", -3, date "Friday, July 16, 1999 1:59:29 PM", date 

"Monday, July 17, 2000 4:56:57 PM", 2.121269248E+9, 1.494134784E+9, false}

disk cache settings

This class is the return value for the Memory application's disk cache property. Since this is a subclass of memory settings, you can find out about the computer's disk cache with code such as the following (state and size are properties of the memory settings super class):

state of disk cache or size of disk cache

If you are like me, you might want to try to look at the disk cache settings object with code, such as:

tell app "Memory" to get disk cache

But this syntax raises a script error. You have to get or set only the size or state properties.

memory settings

This is the super class for disk cache, RAM disk, and virtual memory settings classes. Therefore, each of these classes have the state and size properties, too (because AppleScript subclasses, in most circumstances, inherit their parent class's properties).

state constant

This property specifies whether or not the memory setting, such as virtual memory, is active. It can be one of the following constants: active, inactive, active after restart, or inactive after restart. For example, if virtual memory is "off" in the control panel, then

state of virtual memory

returns the constant inactive (or inactive after restart if you just switched VM off in the Memory control panel).

size integer (or minimum, maximum, default)

This is the amount of memory or disk space allocated in bytes to the disk cache, RAM disk, or virtual memory. You can set the amount in bytes:

set size of disk cache to (size of disk cache + (1024 * 1024))

Or use one of these constants: minimum, maximum,or default. If you use an AppleScript to:

set size of disk cache to maximum

then the Memory control panel will show a new custom setting in its disk cache area. The new setting takes effect when the computer is restarted.

RAM disk settings

This class is returned by getting the Memory application's RAM disk property:

tell app "Memory" to get persistence of RAM disk

The script raises an error if it tries to use syntax, such as:

tell app "Memory" to get RAM disk

You have to get the size, state, or persistence properties in code that references the RAM disk settings.

persistence boolean

If the RAM disk will keep its contents after a computer has been shut down and restarted, then this property is true. A RAM disk is a segment of RAM set aside and used as if it were a disk on the desktop. You can drag folders and files into it, but the disk contents on some systems are lost if the computer is shut down or loses power.

virtual memory settings

This class is returned by getting the Memory application's virtual memory property, as in:

tell app "Memory" to get configured volume of virtual

memory

This code fragment returns the disk used to hold virtual memory. The script will raise an error if it tries to use syntax, such as:

tell app "Memory" to get virtual memory

You have to get the size, state, or configured volume of this object; virtual memory itself is not directly accessible. Even if virtual memory is currently "off" in the Memory control panel, getting its size property will still return the number of bytes that would be reserved for it if VM were on. Find out whether it is on by getting the state of virtual memory. See the memory settings class description.

configured volume available disk

The configured volume property returns the disk as an available disk object that stores virtual memory. See the available disk class.

    Team LiB   Previous Section   Next Section