DekGenius.com
Team LiB   Previous Section   Next Section
Standard Additions

Dictionary classes

dialog reply

This record object is the return value of the display dialog scripting addition. display dialog displays a message in a modal dialog window (i.e., a window that appears in front of other windows), optionally requests the user to enter some text in an edit field, and optionally closes itself after a specified number of seconds. A record is a series of name/value pairs separated by commas and surrounded by a pair of curly braces. The return value for the following example looks like this:

{text returned:"Bruce", button returned:"OK", gave up:false}

Your return value will only include the gave up property if the display dialog command included the giving up after parameter when the command was used, as in display dialog "Tired of me yet?" giving up after 10.

set rep to (display dialog "Identify yourself please." default¬
answer "" giving up after 30)
(*
the variable rep could contain this:
{text returned:"Bruce", button returned:"OK", gave up:false}
*)

The following are dialog reply properties:

button returned string (read-only)

This property returns the label of the button the user clicked on the dialog. You can get this value with code such as:

set theButton to (button returned of the result)

text returned string (read-only)

This property returns the text (if any) the user entered in the edit field of the dialog. You can get this value with code such as:

set theText to (text returned of the result)

gave up boolean (read-only)

Your script might want to take some default action if the dialog had to dismiss itself because the user failed to interact with the dialog window. For example, the code:

display dialog "Enter your name please." default answer ""¬ giving up after 30

closes the window after 30 seconds. If this happens, then the window's return value (a dialog reply record) will include the value gave up: true. dialog reply does not contain a gave up value if you did not use the giving up after parameter with display dialog.

file information

This record is returned by the info for scripting addition. A pretty simple code phrase for getting file information is:

set f to (info for (choose file))

The choose file scripting addition lets the user choose a file, then returns an alias type for handling by the info for osax. Here is a look at a sample return value:

{name:"applescript.doc", creation date:date "Saturday, May 20,
2000 9:57:58 AM", modification date:date "Saturday, May 20, 2000 9:57:58 AM",
icon position:{0, 0}, visible:true, size:23877, folder:false, alias:false,
locked:false, busy status:true, file creator:"MSWD", file type:"BINA", short
version:"", long version:"", default application:alias "Macintosh HD:Microsoft
Office 98:Microsoft Word"}

name international text (read-only)

This string returns the name of the file.

size integer (read-only)

This number is the size in bytes of the file on disk, such as 23877.

Mac OS X returns this size value as a real data type to accommodate files that are greater than two gigabytes in size.

creation date date (read-only)

This value returns a date object for when the file was created.

modification date date (read-only)

This value returns a date object for when the file was last modified, such as:

date "Saturday, May 20, 2000 9:57:58 AM"

file type string (read-only)

This value is the four-character Mac file type, as in "TEXT" for text files.

file creator string (read-only)

This property is the four-character Mac creator type, as in "R*ch" for BBEdit files or "MSWD" for Word files.

default application alias (read-only)

This is an alias type that identifies the path to the program that would open if you double-clicked this file. For example:

alias "Macintosh HD:Microsoft Office 98:Microsoft Word"

visible boolean (read-only)

Is the file or folder visible? If yes, then this property is true.

icon position point (read-only)

These are the coordinates for the upper-left-hand corner of the file's or folder's icon, in the form {50,50}.

folder window bounding rectangle (read-only)

If the item is a folder, these are the coordinates of the upper left and lower right corners of the folder window. The return value looks something like {557, 90, 880, 332}.

folder boolean (read-only)

This is true if the item is a folder.

alias boolean (read-only)

If the item is an alias (rather than a non-alias file or folder), this value is true.

locked boolean (read-only)

If the file is not locked then this value is false. You can lock a file by selecting it, clicking Command-I, and checking the "locked" checkbox in the resulting window. Its icon will have a little padlock on it, and any changes in the file cannot be saved.

short version string (read-only)

The short and long versions apply to the version information in a Get Info window of a file (usually an application). For example, my Script Editor's short version value is "1.4.3."

long version string (read-only)

The short and long versions apply to the version information in a Get Info window of a file (usually an application). For example, my Script Editor's long version value is "1.4.3, Copyright Apple Computer, Inc. 1997-2000."

busy status boolean (read-only)

If the file is busy or being used by a program, its busy status is true.

FTP item

This class or object represents a folder or a file on an FTP server. Here's a peek inside a hypothetical FTP object:

{class:FTP item, name:"index.html", URL:{class:URL, scheme:ftp URL, 
path:"ftp://user_name:.........@12.16.160.221/", user name:"user_name", 
password:".........", host:{class:Internet address, DNS form:"12.16.160.221", 
port:21, dotted decimal form:"12.16.160.221"}}, kind:"file"}

The following are FTP item properties:

properties record

This is a record type containing the gettable or settable properties of the FTP object.

name string (read-only)

This string property is the name of the FTP item.

URL URL (read-only)

This is the URL object for the FTP item. See the URL class.

kind string (read-only)

This property identifies whether the FTP object is a file or folder.

Internet Address

The host property of a URL object (see the URL class later in this chapter) returns this object, which represents basically an IP address (e.g., 12.16.162.122), a hostname (e.g., www.yahoo.com), and a port number (e.g., 80). An example Internet Address object is:

{class:Internet address, DNS form:"www.parkerriver.com", port:80, dotted 
decimal form:"12.16.160.223"}

The following are Internet Address properties:

properties record

This property returns the Internet Address' properties as a record type (although I can only get an empty record ({ }) when attempting to access this value).

DNS form string

This is the Domain Name System name of the web address or the human-readable form of the Internet Address (e.g., my.yahoo.com, as opposed to the dotted decimal numerical form).

dotted decimal form string

This string represents the IP address of the Internet Address, as in "216.115.105.16."

port integer

This number represents the port number for the TCP/IP service, as in 80 for the HTTP protocol and 21 for FTP.

URL

This object represents an Internet URL, such as a web, FTP, or newsgroup resource. If your machine is connected to the Web, then the following example will quickly give you the IP address of the web site for which you supply the hostname:

set wAdd to (the text returned of¬
(display dialog "Enter the Web address:" default answer "http://"))
try -- catch user errors entering Web address
   set theURL to wAdd as URL
   display dialog (dotted decimal form of (host of theURL))
   on error
   display dialog "Try me again; you probably mistyped the Web host¬
   name."
end try

The following are URL properties:

properties record

This is a record type containing the URL properties as name/value pairs.

name string (read-only)

Some URL objects do not have a name property and raise an error if you try to access it. If appropriate, this property represents a name, such as a filename.

scheme constant (read-only)

The scheme can be one of these constants: http URL/secure http URL/ftp URL/mail URL/file URL/gopher URL/telnet URL/news URL/secure news URL/nntp URL/message URL/mailbox URL/multi URL/launch URL/afp URL/AppleTalk URL/remote application URL/streaming multimedia URL/network file system URL/. For example, a web page URL object has a scheme of http URL.

host Internet Address

The host property returns an Internet Address object (see the Internet Address class). The example under the "URL" section grabs the IP address of a web site by accessing the dotted decimal form property of a URL object's host property.

path string

This string contains the virtual path on the server, which is often the same as the entire URL, as in http://www.parkerriver.com/index.html.

user name string

An FTP URL often has a username property. For example, the URL ftp://my_user_name:mypassw12@12.16.160.221/ has a username property of "my_user_name."

password string

An FTP URL often has a password property. For example, the URL ftp://my_user_name:mypassw12@12.16.160.221/ has a password property of "mypassw12."

web page

This is a class that represents a web page. The following are web page properties:

properties record

This record contains a series of name/value pairs that comprise the web page's properties. Chapter 3describes the record type.

name string

This string is the name of the web page, such as index.html.

URL URL

This is the URL object of the web page. See the URL class.

text encoding string

This is the text-encoding method used for this page. One encoding method is "application/x-www-form-urlencoded," which is used for form values that are sent from a web page to a server program.

    Team LiB   Previous Section   Next Section