メインコンテンツまでスキップ
バージョン:23.5

Global Properties for Working with URLs and Sockets

If you are working with URLs, sockets, and processes in your SenseTalk scripts, the following global properties let you change timeout values and cache behavior.

For information about working with URLs and sockets in SenseTalk, see Socket, Process, and Stream Input and Output and URL Transactions and Formatting.

Setting or Changing Local and Global Property Values:

You can set a global property value with the SenseTalk commands Set or Put. Note that when you reference one of these properties, you must use the word the before the property name to distinguish it from an ordinary variable.

Examples:

set the searchrectangle to [1,2,2,3]
put 2 into the remoteworkinterval

You can add or change specific named properties within a global property like this:

set the namedColors.pink to color("RGB,1.0,0.5,0.5") -- Adds pink to the namedColors global property and defines its RGB color value
set the listFormat's separator to " & " -- Sets the separator property of the listFormat global property

Properties can also be set or updated by using the setoption or setoptions commands. The setoption command lets you update a single property, and setoptions lets you update multiple properties.

Examples:

setoption searchrectangle, [1,2,2,3]
setoptions {searchrectangle: [1,2,2,3], scriptlogging: yes}
ノート

Because setoption and setoptions are specific for use with global and local properties, you omit the word the from the property name in the command syntax for these commands.

For additional information about working with local and global properties, see Local and Global Properties in SenseTalk.

the URLCacheEnabled Global Property

Values: True, False

Default: True

Behavior: This global property controls whether the contents retrieved from a URL resource can be cached. When set to True (the default), URL contents can be cached by the system and retrieved from the cache rather than being fetched remotely each time. To force a fresh copy of the URL to be loaded, set the URLCacheEnabled property to False before accessing a URL.

Example:

set the URLCacheEnabled to false

Example:

set the URLCacheEnabled to false
put url "http://www.apple.com" into appleHomePage -- Get a fresh copy
set the URLCacheEnabled to true -- Restore caching

the URLTimeout Global Property

Values: A time value, in seconds

Default: 30 seconds

Behavior: This global property specifies the maximum time allowed before a URL resource request times out. If this time limit is exceeded or there is no Internet connection available, or if some other error occurs, the result() function returns an exception object identifying the error, which can be accessed on the next line of the script.

Example:

set the URLTimeout to 45

Example:

set the URLTimeout to 10
put url "http://google.com"

the URLErrorLevel Global Property

Values: An integer

Default: 400

Behavior: This global property value indicates the lowest URL status code that is treated as an error when fetching the contents of a URL. The default value is 400, so a returned status value of 400 or above either throws an exception or sets the result() function to an exception (depending on the current setting of the throwExceptionResults global property). You can set the URLErrorLevel to zero (or to any sufficiently large number) to prevent this type of exception from being generated.

Example:

set the URLErrorLevel to 450

Example:

set the URLErrorLevel to 300
set the throwExceptionResults to false
put url "http://localhost:8080/api/test"
put the result into Problem
if Problem Contains "401" then
log "Unauthorized."
else if Problem Contains "307" then
log "Redirected"
end if

the readTimeout Global Property

Values: A time value, in seconds

Default: 30 seconds

Behavior: This property sets the maximum time the read command waits for data to become available from a socket, process, or file. If the requested data is not read within the time specified by the readTimeout, whatever has been read is returned and the result() function is set to indicate time out. If reading from a socket and the socket is unavailable within the time limit, an exception is thrown.

Example:

set the readTimeout to 60

Example:

set the readtimeout to 5
open process "skype"
read from process "skype" until end // Tries reading the process for 5 seconds
put the result // Displays 'time oseut'
close process "skype"

Related: