Commands

open

Supported By

Syntax

open object [as method]

open applicationPath

open documentPath (with|in) applicationPath

Object yields an object with an appropriate I/O manager. Method yields the name of an I/O method. DocumentPath and applicationPath yield file paths to a document file and an application file, respectively.

Description

The open command, when given an object with an appropriate I/O manager (e.g., a file or URL), opens an object for reading or writing. If the object is a file and the file does not exist, the file I/O manager creates it.

If the parameter to the open command does not have an appropriate I/O manager or is not an object, or if the with or in parameter is given, the open command launches an application or document. The open command without a with or in parameter first looks for applications, then documents. The open command with a with or in parameter opens the file documentPath with the application applicationPath regardless of what application would normally open the file. In OpenXION, the locations searched for applications and documents are determined by the applicationPaths and documentPaths properties, respectively. In HyperTalk, the locations searched for applications and documents are determined by the global variables Applications and Documents.

Scripts

The following example opens a file, reads a line of data from it, then closes the file:

on printALine
  open file "MyFile"
  read from file "MyFile"
  put it
  close file "MyFile"
end printALine

The following example opens a URL with the user's default web browser:

on myLink
  open url "http://www.openxion.org"
end myLink

The following example opens a URL and reads its contents:

on readURL
  open URL "http://www.openxion.org/" as "text"
  read from URL "http://www.openxion.org/" until eof
  put it
  close URL "http://www.openxion.org/"
end readURL

The following example queries the user for a document and application before executing the open command:

on openSomething
  answer file "Select a document:"
  if it is not empty then
    put it into doc
    answer file "Select an application:"
    if it is not empty then open doc with it
  end if
end openSomething

Note

If the open applicationPath or open documentPath with applicationPath form is used and the specified application or document cannot be found, the interpreter must present a prompt to the user asking them to select the appropriate file. To avoid this prompt, you can use the appPath, appFile, docPath, docFile, appOrDocPath, or appOrDocFile functions. If the function returns empty, then the application or document cannot be found.

Security

To launch applications and documents, OpenXION's security settings must allow the FILE_LAUNCH security key. To open an object with an I/O manager, any security keys required are determined by the I/O manager (e.g., file or URL); see the documentation for the I/O manager itself. If the required security key is denied, a script error will be triggered.

Compatibility

HyperTalk does not support the as parameter or reading from or writing to URLs.

See Also

read, write, truncate, close, file, text, binary