FileTypes

The FileTypes class provides the means for identifying files by their kind, type identifier, or display name.

Common FileTypes

Data and information are often shared as files in standard formats such as plain or rich text (txt, rtf), images (TIFF, JPEG, PNG, etc.), and as organized data archives (JSON, XML, and Property Lists). To enable these types of files to be used with Omni Automation scripts, they have been assigned the following default class property values:

To create an instance of one of these generalized types, append the class property name to the FileType class name, like this:

FileType Instance Properties

Every instance of a FileType has read-only properties whose values can be accessed via a script:

You can use these instance properties to return information for any file type:

FileType.binaryPropertyList.displayName //-> binary property list FileType.binaryPropertyList.identifier //-> com.apple.binary-property-list FileType.binaryPropertyList.pathExtensions //-> ["plist"]

Application Specific FileTypes

Every Omni application that supports Omni Automation has document types specific to that application. These document types are grouped as either readable or writeable by the host application.

Use the following FileType class properties to retrieve lists of the document types contained within each group:

FileType.readableTypes.map(function(fType){return fType.displayName})
FileType.readableTypes.map(function(fType){return fType.displayName})
FileType.writableTypes.map(function(fType){return fType.displayName})
FileType.writableTypes.map(function(fType){return fType.identifier})
FileType.writableTypes.map(function(fType){return fType.pathExtensions})
FileType.writableTypes.map(function(fType){return fType.displayName})
FileType.writableTypes.map(function(fType){return fType.identifier})
FileType.writableTypes.map(function(fType){return fType.pathExtensions})

Creating a FileType Instance

Instances of the FileType class are created using the standard JavaScript new constructor. Simply provide the corresponding identifier to the desired file type:

fType = new FileType("com.omnigroup.omnigraffle.graffle") console.log(fType.displayName) console.log(fType.pathExtensions)
fType = new FileType("public.plain-text") console.log(fType.displayName) console.log(fType.pathExtensions)

Checking a FileType Instance

On occasion your scripts may need to compare instances of file types. The conformsTo(…) method of the FileType class, when called upon an instance of a file type, will return a boolean value of true if the provided comparison file type instance is the same or a more specific version of the provided comparison file type:

For example, a PNG file type is a more specific variant of the image file type, whereas a PNG file type does not match and is not a more specific variant of the plain text file type:

FileType.png.conformsTo(FileType.image) FileType.png.conformsTo(FileType.plainText)
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER